changeset 52717:a7669e7b0355 stable

narrow: stricter validation of narrowspec patterns Forbid whitespace at the edges of the pattern because it just doesn't work correctly.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Fri, 10 Jan 2025 12:40:42 +0000
parents 9cf807501e27
children 1c83ebf78f74
files mercurial/narrowspec.py tests/test-narrow.t
diffstat 2 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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(
--- a/tests/test-narrow.t	Thu Jan 16 17:06:15 2025 +0100
+++ b/tests/test-narrow.t	Fri Jan 10 12:40:42 2025 +0000
@@ -59,6 +59,9 @@
   $ hg clone --narrow ssh://user@dummy/master foo --include a/./c
   abort: "." and ".." are not allowed in narrowspec paths
   [255]
+  $ hg clone --narrow ssh://user@dummy/master foo --include ' '
+  abort: leading or trailing whitespace is not allowed in narrowspec paths
+  [255]
 
 Names with '.' in them are OK.
   $ hg clone --narrow ./master should-work --include a/.b/c