Skip to content

Commit 401f991

Browse files
authored
Fix string lookup in MatchSpec parsing (#4040)
1 parent abf6525 commit 401f991

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

libmamba/src/specs/match_spec.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,17 @@ namespace mamba::specs
456456
}
457457

458458
pos = str.find_last_of('=');
459-
const char d = str[pos - 1];
459+
if (pos == str.npos)
460+
{
461+
// That means that there is no operator, and version and build are separated with
462+
// space(s)
463+
pos = str.find_last_of(' ');
464+
return { util::strip(str.substr(0, pos)), str.substr(pos + 1) };
465+
}
460466

467+
assert(pos != str.npos);
468+
assert(pos < str.size());
469+
const char d = str[pos - 1];
461470
if (d == '=' || d == '!' || d == '|' || d == ',' || d == '<' || d == '>' || d == '~')
462471
{
463472
// Find the position of the first non-space character after operator
@@ -475,14 +484,6 @@ namespace mamba::specs
475484
return { str, {} };
476485
}
477486

478-
if (pos == str.npos)
479-
{
480-
// That means that there is no operator, and version and build are separated with
481-
// space(s)
482-
pos = str.find_last_of(' ');
483-
return { util::strip(str.substr(0, pos)), str.substr(pos + 1) };
484-
}
485-
486487
// '=' is found but not combined with `d` above
487488
// meaning that the build is right after the last '='
488489
const auto build_start = str.find_first_not_of(' ', pos + 1);

0 commit comments

Comments
 (0)