summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2022-12-23 08:23:03 -0500
committerNed Batchelder <ned@nedbatchelder.com>2022-12-23 08:23:03 -0500
commit152cdc7a2b654b16fb572856d03097580e06e127 (patch)
tree1cfda3fea3b616adb7528d30621ffcad4382f2c1
parent31513b4b0559fdc7578aa1a30e048b928dc46188 (diff)
downloadpython-coveragepy-git-152cdc7a2b654b16fb572856d03097580e06e127.tar.gz
fix: don't forbid plus signs in file names. #1513
-rw-r--r--CHANGES.rst4
-rw-r--r--coverage/files.py2
-rw-r--r--tests/test_files.py10
3 files changed, 13 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 53d17133..8355fed8 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -20,9 +20,13 @@ development at the same time, such as 4.5.x and 5.0.
Unreleased
----------
+- File pattern rules were too strict, forbidding plus signs and curly braces in
+ directory and file names. This is now fixed, closing `issue 1513`_.
+
- The PyPy wheel now installs on PyPy 3.7, 3.8, and 3.9, closing `issue 1510`_.
.. _issue 1510: https://github.com/nedbat/coveragepy/issues/1510
+.. _issue 1513: https://github.com/nedbat/coveragepy/issues/1513
.. _changes_7-0-0:
diff --git a/coverage/files.py b/coverage/files.py
index 5f222419..7443f8c9 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -325,7 +325,7 @@ G2RX_TOKENS = [(re.compile(rx), sub) for rx, sub in [
(r"\?", r"[^/\\\\]"), # ? matches one non slash-like
(r"\[.*?\]", r"\g<0>"), # [a-f] matches [a-f]
(r"[a-zA-Z0-9_-]+", r"\g<0>"), # word chars match themselves
- (r"[\[\]+{}]", None), # Can't have regex special chars
+ (r"[\[\]]", None), # Can't have single square brackets
(r".", r"\\\g<0>"), # Anything else is escaped to be safe
]]
diff --git a/tests/test_files.py b/tests/test_files.py
index 9e49628d..29bd9a0d 100644
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -230,10 +230,18 @@ def globs_to_regex_params(
matches=["foo", "hello/foo", "hi/there/foo"],
nomatches=["foob", "hello/foob", "hello/Foo"],
),
+ globs_to_regex_params(
+ ["a+b/foo*", "x{y}z/foo*"],
+ matches=["a+b/foo", "a+b/foobar", "x{y}z/foobar"],
+ nomatches=["aab/foo", "ab/foo", "xyz/foo"],
+ ),
]))
)
def test_globs_to_regex(patterns, case_insensitive, partial, text, result):
regex = globs_to_regex(patterns, case_insensitive=case_insensitive, partial=partial)
+ print(patterns)
+ print(regex)
+ print(text)
assert bool(regex.match(text)) == result
@@ -243,8 +251,6 @@ def test_globs_to_regex(patterns, case_insensitive, partial, text, result):
("*****/foo.py", "*****"),
("Hello]there", "]"),
("Hello[there", "["),
- ("Hello+there", "+"),
- ("{a,b}c", "{"),
("x/a**/b.py", "a**"),
("x/abcd**/b.py", "abcd**"),
("x/**a/b.py", "**a"),