Skip to content

Commit d8f2835

Browse files
authored
Merge pull request #198 from facelessuser/bugfix/windows-path
Fix Windows drive normalization and pattern indexing with implied drives
2 parents 1b1bbe9 + 2e8b747 commit d8f2835

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

docs/src/markdown/about/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 8.4.1
4+
5+
- **FIX**: Windows drive path separators should normalize like other path separators.
6+
- **FIX**: Fix a Windows pattern parsing issue that caused absolute paths with ambiguous drives to not parse correctly.
7+
38
## 8.4
49

510
- **NEW**: Drop support for Python 3.6.

tests/test_glob.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,13 +1591,29 @@ def test_selflink(self):
15911591
class TestGlobPaths(unittest.TestCase):
15921592
"""Test `glob` paths."""
15931593

1594-
def test_root(self):
1594+
@unittest.skipUnless(not sys.platform.startswith('win'), "Linux/Unix specific test")
1595+
def test_root_unix(self):
15951596
"""Test that `glob` translates the root properly."""
15961597

1597-
# On Windows, this should translate to the current drive.
15981598
# On Linux/Unix, this should translate to the root.
15991599
# Basically, we should not return an empty set.
1600-
self.assertTrue(len(glob.glob('/*')) > 0)
1600+
results = glob.glob('/*')
1601+
self.assertTrue(len(results) > 0)
1602+
self.assertTrue('/' not in results)
1603+
1604+
@unittest.skipUnless(sys.platform.startswith('win'), "Windows specific test")
1605+
def test_root_win(self):
1606+
"""Test that `glob` translates the root properly."""
1607+
1608+
# On Windows, this should translate to the current drive.
1609+
# Basically, we should not return an empty set.
1610+
results = glob.glob('/*')
1611+
self.assertTrue(len(results) > 0)
1612+
self.assertTrue('\\' not in results)
1613+
1614+
results = glob.glob(r'\\*')
1615+
self.assertTrue(len(results) > 0)
1616+
self.assertTrue('\\' not in results)
16011617

16021618
def test_start(self):
16031619
"""Test that starting directory/files are handled properly."""

wcmatch/__meta__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,5 @@ def parse_version(ver: str) -> Version:
193193
return Version(major, minor, micro, release, pre, post, dev)
194194

195195

196-
__version_info__ = Version(8, 4, 0, "final")
196+
__version_info__ = Version(8, 4, 1, "final")
197197
__version__ = __version_info__._get_canonical()

wcmatch/_wcparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ def _get_win_drive(
362362
end = m.end(0)
363363
if m.group(3) and RE_WIN_DRIVE_LETTER.match(m.group(0)):
364364
if regex:
365-
drive = escape_drive(RE_WIN_DRIVE_UNESCAPE.sub(r'\1', m.group(3)), case_sensitive)
365+
drive = escape_drive(RE_WIN_DRIVE_UNESCAPE.sub(r'\1', m.group(3)).replace('/', '\\'), case_sensitive)
366366
else:
367-
drive = RE_WIN_DRIVE_UNESCAPE.sub(r'\1', m.group(0))
367+
drive = RE_WIN_DRIVE_UNESCAPE.sub(r'\1', m.group(0)).replace('/', '\\')
368368
slash = bool(m.group(4))
369369
root_specified = True
370370
elif m.group(2):

wcmatch/glob.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,12 @@ def split(self) -> List[_GlobPart]:
314314
i.advance(start)
315315
elif drive is None and root_specified:
316316
parts.append(_GlobPart(b'\\' if is_bytes else '\\', False, False, True, True))
317-
start = 1
318-
i.advance(2)
317+
if pattern.startswith('/'):
318+
start = 0
319+
i.advance(1)
320+
else:
321+
start = 1
322+
i.advance(2)
319323
elif not self.win_drive_detect and pattern.startswith('/'):
320324
parts.append(_GlobPart(b'/' if is_bytes else '/', False, False, True, True))
321325
start = 0

0 commit comments

Comments
 (0)