changeset 24811:a2dcf460e141 stable

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 17 Apr 2015 14:12:01 -0700
parents f5416657e661
children e4e69cebeedd
files tests/run-tests.py tests/test-run-tests.t
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Fri Apr 17 09:46:43 2015 -0700
+++ b/tests/run-tests.py	Fri Apr 17 14:12:01 2015 -0700
@@ -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 == '*':
--- a/tests/test-run-tests.t	Fri Apr 17 09:46:43 2015 -0700
+++ b/tests/test-run-tests.t	Fri Apr 17 14:12:01 2015 -0700
@@ -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
+