mercurial/narrowspec.py
branchstable
changeset 52717 a7669e7b0355
parent 51859 f4733654f144
child 52718 1c83ebf78f74
--- a/mercurial/narrowspec.py	Thu Jan 16 17:06:15 2025 +0100
+++ b/mercurial/narrowspec.py	Fri Jan 10 12:40:42 2025 +0000
@@ -68,6 +68,16 @@
     if _numlines(pat) > 1:
         raise error.Abort(_(b'newlines are not allowed in narrowspec paths'))
 
+    # patterns are stripped on load (see sparse.parseconfig),
+    # so a pattern ending in whitespace doesn't work correctly
+    if pat.strip() != pat:
+        raise error.Abort(
+            _(
+                b'leading or trailing whitespace is not allowed '
+                b'in narrowspec paths'
+            )
+        )
+
     components = pat.split(b'/')
     if b'.' in components or b'..' in components:
         raise error.Abort(