From 152cdc7a2b654b16fb572856d03097580e06e127 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 23 Dec 2022 08:23:03 -0500 Subject: [PATCH] fix: don't forbid plus signs in file names. #1513 --- CHANGES.rst | 4 ++++ coverage/files.py | 2 +- tests/test_files.py | 10 ++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 53d171331..8355fed88 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 5f2224195..7443f8c9a 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -325,7 +325,7 @@ def sep(s): (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 9e49628d5..29bd9a0d0 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"),