summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2011-08-22 07:42:17 -0400
committerNed Batchelder <ned@nedbatchelder.com>2011-08-22 07:42:17 -0400
commitc818b43e3e16df67feb73d3e0b751f096c6e5cf0 (patch)
tree6fa76977dc4ef9c577eff3ca9cc25d0b7ca33d16
parent8a745e7b1820db4642f45893655207b9ef1acf97 (diff)
downloadpython-coveragepy-c818b43e3e16df67feb73d3e0b751f096c6e5cf0.tar.gz
PathAliases munges the fnmatch pattern, and could have accidentally borked the match.
-rw-r--r--coverage/files.py2
-rw-r--r--test/test_files.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/coverage/files.py b/coverage/files.py
index 23f1bde..93a5ab2 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -164,7 +164,7 @@ class PathAliases(object):
# Make a regex from the pattern. fnmatch always adds a \Z or $ to
# match the whole string, which we don't want.
- regex_pat = fnmatch.translate(pattern).replace(r'\Z', '')
+ regex_pat = fnmatch.translate(pattern).replace(r'\Z(', '(')
if regex_pat.endswith("$"):
regex_pat = regex_pat[:-1]
regex = re.compile("(?i)" + regex_pat)
diff --git a/test/test_files.py b/test/test_files.py
index 2f26c7b..565bbaa 100644
--- a/test/test_files.py
+++ b/test/test_files.py
@@ -120,6 +120,13 @@ class PathAliasesTest(CoverageTest):
aliases.add, "/ned/home/*/*/", "fooey"
)
+ def test_no_accidental_munging(self):
+ aliases = PathAliases()
+ aliases.add(r'c:\Zoo\boo', 'src/')
+ aliases.add('/home/ned$', 'src/')
+ self.assertEqual(aliases.map(r'c:\Zoo\boo\foo.py'), 'src/foo.py')
+ self.assertEqual(aliases.map(r'/home/ned$/foo.py'), 'src/foo.py')
+
def test_paths_are_os_corrected(self):
aliases = PathAliases()
aliases.add('/home/ned/*/src', './mysrc')