# HG changeset patch # User Gregory Szorc # Date 2015-04-17 21:12:01 # Node ID a2dcf460e141fa5979d3b29cce76b958d5b68b94 # Parent f5416657e661b3d2d811efb64ea5cf1648080cc9 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. 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 @@ class TTest(Test): 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 @@ test for --json } (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 +