Skip to content

Commit 66657c1

Browse files
committed
fix: path-mapped results shouldn't start with ./
Unless the actual result in the config starts with ./
1 parent bb27eb6 commit 66657c1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

coverage/files.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ def map(self, path):
435435
new = new.replace(sep(path), sep(result))
436436
if not self.relative:
437437
new = canonical_filename(new)
438+
dot_start = result.startswith(("./", ".\\")) and len(result) > 2
439+
if new.startswith(("./", ".\\")) and not dot_start:
440+
new = new[2:]
438441
self.debugfn(
439442
f"Matched path {path!r} to rule {original_pattern!r} -> {result!r}, " +
440443
f"producing {new!r}"

tests/test_files.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,13 @@ def test_no_accidental_match(self, rel_yn):
380380
aliases.add('/home/*/src', './mysrc')
381381
self.assert_unchanged(aliases, '/home/foo/srcetc')
382382

383+
def test_no_dotslash(self, rel_yn):
384+
# The result shouldn't start with "./" if the map result didn't.
385+
aliases = PathAliases(relative=rel_yn)
386+
aliases.add('*/project', '.')
387+
# Because the map result has no slash, the actual result is os-dependent.
388+
self.assert_mapped(aliases, '/ned/home/project/src/a.py', f'src{os.sep}a.py')
389+
383390
def test_multiple_patterns(self, rel_yn):
384391
# also test the debugfn...
385392
msgs = []

0 commit comments

Comments
 (0)