C#: Fix glob pattern processing: allow **/ to match empty string

This commit is contained in:
Tamas Vajk
2024-07-03 08:09:30 +02:00
parent c7ad0ad406
commit b36db5ad11
3 changed files with 54 additions and 9 deletions

View File

@@ -76,8 +76,20 @@ namespace Semmle.Extraction
throw new InvalidFilePatternException(pattern, "'**' preceeded by non-`/` character.");
if (HasCharAt(i + 2, c => c != '/'))
throw new InvalidFilePatternException(pattern, "'**' succeeded by non-`/` character");
sb.Append(".*");
i += 2;
if (i + 2 < pattern.Length)
{
// Processing .../**/...
sb.Append("(.*/|)");
i += 3;
}
else
{
// Processing .../**
sb.Append(".*");
// There's no need to add another .* to the end outside the loop, we can return early.
return sb;
}
}
else
{