#16618: Make glob.glob match consistently across strings and bytes
Fixes handling of leading dots.
Patch by Serhiy Storchaka.
diff --git a/Lib/glob.py b/Lib/glob.py
index 58888d6..f16e8e1 100644
--- a/Lib/glob.py
+++ b/Lib/glob.py
@@ -58,8 +58,8 @@
names = os.listdir(dirname)
except os.error:
return []
- if pattern[0] != '.':
- names = [x for x in names if x[0] != '.']
+ if not _ishidden(pattern):
+ names = [x for x in names if not _ishidden(x)]
return fnmatch.filter(names, pattern)
def glob0(dirname, basename):
@@ -83,3 +83,6 @@
else:
match = magic_check.search(s)
return match is not None
+
+def _ishidden(path):
+ return path[0] in ('.', b'.'[0])