From 8861b2911c15b34aecfa86d28f46b0849e9a451b Mon Sep 17 00:00:00 2001 From: Ian Thomas Date: Fri, 7 Jul 2023 13:14:53 +0100 Subject: [PATCH] Match escaped square brackets in paths literally not as regexes --- fsspec/spec.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fsspec/spec.py b/fsspec/spec.py index 2bdfa3854..03c58f669 100644 --- a/fsspec/spec.py +++ b/fsspec/spec.py @@ -603,6 +603,11 @@ def glob(self, path, **kwargs): ) pattern = re.sub("[*]{2}", "=PLACEHOLDER=", pattern) pattern = re.sub("[*]", "[^/]*", pattern) + + # Replace \\[ with \[ and \\] with \], which ensures that user-specified + # escaped square brackets are matched literally and not as regexes. + pattern = re.sub(r"\\\\([\[\]])", r"\\\1", pattern) + pattern = re.compile(pattern.replace("=PLACEHOLDER=", ".*")) out = { p: allpaths[p]