diff --git a/.changeset/dockerignore-ascii-digit-class.md b/.changeset/dockerignore-ascii-digit-class.md new file mode 100644 index 0000000000..27cef05799 --- /dev/null +++ b/.changeset/dockerignore-ascii-digit-class.md @@ -0,0 +1,5 @@ +--- +"@e2b/dockerfile-utils-python": patch +--- + +Keep bracket digit classes in Dockerignore patterns ASCII-only, matching Moby and the JavaScript utility. Non-ASCII decimal digits are no longer excluded by a pattern such as `[\d]`. diff --git a/packages/dockerfile-utils-python/e2b_dockerfile_utils/dockerignore.py b/packages/dockerfile-utils-python/e2b_dockerfile_utils/dockerignore.py index 18e6d7448f..9353ffd4f5 100644 --- a/packages/dockerfile-utils-python/e2b_dockerfile_utils/dockerignore.py +++ b/packages/dockerfile-utils-python/e2b_dockerfile_utils/dockerignore.py @@ -144,7 +144,7 @@ def _compile(pattern: str, backslash_is_escape: bool) -> Callable[[str], bool]: return lambda path: path.endswith(suffix) or ( suffix.startswith("/") and path == suffix[1:] ) - compiled = re.compile(regex + r"\Z") + compiled = re.compile(regex + r"\Z", flags=re.ASCII) return lambda path: compiled.match(path) is not None diff --git a/packages/dockerfile-utils-python/tests/test_dockerignore.py b/packages/dockerfile-utils-python/tests/test_dockerignore.py index 4bed4766a3..9902943d4a 100644 --- a/packages/dockerfile-utils-python/tests/test_dockerignore.py +++ b/packages/dockerfile-utils-python/tests/test_dockerignore.py @@ -72,3 +72,11 @@ def test_rejects_invalid_patterns_with_value_error(): PatternMatcher(["[abc"]) with pytest.raises(ValueError, match=r"Invalid ignore pattern '\[\\q\]'"): PatternMatcher(["[\\q]"]) + + +@pytest.mark.parametrize( + ("path", "excluded"), + [("5", True), ("\u0661", False), ("d", False)], +) +def test_digit_class_only_matches_ascii_digits(path, excluded): + assert PatternMatcher([r"[\d]"]).matches(path) is excluded