Patchwork [STABLE] run-tests: don't error when glob matched line ends with backslash

login
register
mail settings
Submitter Gregory Szorc
Date April 17, 2015, 9:13 p.m.
Message ID <fd6f10c53bfa25b04602.1429305214@waste.org>
Download mbox | patch
Permalink /patch/8734/
State Accepted
Headers show

Comments

Gregory Szorc - April 17, 2015, 9:13 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1429305121 25200
#      Fri Apr 17 14:12:01 2015 -0700
# Branch stable
# Node ID fd6f10c53bfa25b04602e7792c7bd729fb5a5afd
# Parent  32d0d2f38910d4397b2a05c148e3fb0255588539
run-tests: don't error when glob matched line ends with backslash

As part of writing another test, I triggered an array index error in
glob match processing code by having a (glob) line end in a single
backslash (which is the escape character).

Adding a simple bounds check prevents the error in run-tests.py.
Matt Mackall - April 17, 2015, 10:24 p.m.
On Fri, 2015-04-17 at 16:13 -0500, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1429305121 25200
> #      Fri Apr 17 14:12:01 2015 -0700
> # Branch stable
> # Node ID fd6f10c53bfa25b04602e7792c7bd729fb5a5afd
> # Parent  32d0d2f38910d4397b2a05c148e3fb0255588539
> run-tests: don't error when glob matched line ends with backslash

Queued for stable, thanks.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1065,7 +1065,7 @@ 
         while i < n:
             c = el[i]
             i += 1
-            if c == '\\' and el[i] in '*?\\/':
+            if c == '\\' and i < n and el[i] in '*?\\/':
                 res += el[i - 1:i + 1]
                 i += 1
             elif c == '*':
diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t
--- a/tests/test-run-tests.t
+++ b/tests/test-run-tests.t
@@ -491,3 +491,17 @@ 
   } (no-eol)
 
 #endif
+
+backslash on end of line with glob matching is handled properly
+
+  $ cat > test-glob-backslash.t << EOF
+  >   $ echo 'foo bar \\'
+  >   foo * \ (glob)
+  > EOF
+
+  $ $TESTDIR/run-tests.py --with-hg=`which hg` test-glob-backslash.t
+  .
+  # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
+
+  $ rm -f test-glob-backslash.t
+