Skip to content

Commit 2158eaa

Browse files
committed
Python: Fix a bug in glob regex creation
The previous version was tested on a version of the code where we had temporarily removed the `glob.strip("/")` bit, and so the bug didn't trigger then. We now correctly remember if the glob ends in `/`, and add an extra part in that case. This way, if the path ends with multiple slashes, they effectively get consolidated into a single one, which results in the correct semantics.
1 parent c8cca12 commit 2158eaa

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

python/extractor/semmle/path_filters.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ def glob_to_regex(glob, prefix=""):
5151
parts = parts[:-1]
5252
if not parts:
5353
return ".*"
54+
# The `glob.strip("/")` call above will have removed all trailing slashes, but if there was at
55+
# least one trailing slash, we want there to be an extra part, so we add it explicitly here in
56+
# that case, using the emptyness of `end_sep` as a proxy.
57+
if end_sep == "":
58+
parts += [""]
5459
parts = [ glob_part_to_regex(escape(p), True) for p in parts[:-1] ] + [ glob_part_to_regex(escape(parts[-1]), False) ]
5560
# we need to escape the prefix, specifically because on windows the prefix will be
5661
# something like `C:\\folder\\subfolder\\` and without escaping the

0 commit comments

Comments
 (0)