Skip to content

Commit

Permalink
Early catch regular expression
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <[email protected]>

Co-authored-by: jaimergp <[email protected]>
  • Loading branch information
jjerphan and jaimergp committed Jan 24, 2025
1 parent 43b7188 commit 1dacead
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libmamba/src/specs/regex_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ namespace mamba::specs

RegexSpec::RegexSpec(std::string raw_pattern)
{
// If the string is wrapped in `^` and `$`, `conda.model.MatchSpec` considers it a regex.
// See:
// https://github.com/conda/conda/blob/52b6393d6331e8aa36b2e23ab65766a980f381d2/conda/models/match_spec.py#L134-L139.
// See:
// https://github.com/conda/conda/blob/52b6393d6331e8aa36b2e23ab65766a980f381d2/conda/models/match_spec.py#L889-L894
if (util::starts_with(raw_pattern, pattern_start) && util::ends_with(raw_pattern, pattern_end))
{
m_raw_pattern = raw_pattern;
m_pattern = std::regex(m_raw_pattern);
return;
}

// Construct ss from raw_pattern, in particular make sure to replace all `*` by `.*`
// in the pattern if they are not preceded by a `.`.
// We force regex to start with `^` and end with `$` to simplify the multiple
Expand Down

0 comments on commit 1dacead

Please sign in to comment.