From a7478f499ce6d7ab0c51718aaa3f32534b62829b Mon Sep 17 00:00:00 2001 From: jju1s <123896289+cig13zs@users.noreply.github.com> Date: Thu, 26 Nov 2026 10:35:52 +0800 Subject: [PATCH] Treat a trailing `**\` as an invalid gitignore pattern --- pathspec/patterns/gitignore/spec.py | 5 +++-- tests/test_04_gitignore_spec.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pathspec/patterns/gitignore/spec.py b/pathspec/patterns/gitignore/spec.py index 0e1c7bd..13186ea 100644 --- a/pathspec/patterns/gitignore/spec.py +++ b/pathspec/patterns/gitignore/spec.py @@ -442,9 +442,10 @@ def __translate_segments( # Match whole path segment. out_parts.append('[^/]+') - elif seg == '**\\': + elif seg == '**\\' and i < end: # EDGE CASE: Git does not match a root path with `**\` like it does - # `**`. + # `**`. A final `**\` is a trailing backslash, which is handled + # below as an invalid pattern. out_parts.append('(?s:.+)') else: diff --git a/tests/test_04_gitignore_spec.py b/tests/test_04_gitignore_spec.py index 2c2a0c5..ec8c19e 100644 --- a/tests/test_04_gitignore_spec.py +++ b/tests/test_04_gitignore_spec.py @@ -30,6 +30,8 @@ ]] = [ ('\\', [None, 'literal', 'null'], ['raise']), ('a\\', [None, 'literal', 'null'], ['raise']), + ('**\\', [None, 'literal', 'null'], ['raise']), + ('a/**\\', [None, 'literal', 'null'], ['raise']), ] """ Escaped slash failure test cases.