summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2011-01-12 17:21:11 +0000
committerph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2011-01-12 17:21:11 +0000
commit43dd45d037e060f41e7a6258b8a89a1037e255dc (patch)
tree4b9116b20a432cbf574fafb5de3e1aba59c9b0ee
parentd969301e704b4c098dac92cace9c8770599b15e7 (diff)
downloadpcre-43dd45d037e060f41e7a6258b8a89a1037e255dc.tar.gz
Fix pcregrep bug when --colour was used with -v.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@585 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r--ChangeLog5
-rwxr-xr-xRunGrepTest19
-rw-r--r--pcregrep.c4
-rw-r--r--testdata/grepoutput43
4 files changed, 64 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 36a6d99..34a1c49 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,11 @@ Version 8.12 12-Jan-2011
--match-limit and --recursion-limit options (added for 8.11). In
particular, this made one of the standard tests crash. (The integer value
went into the wrong half of a long int.)
+
+3. If the --colour option was given to pcregrep with -v (invert match), it
+ did strange things, either producing crazy output, or crashing. It should,
+ of course, ignore a request for colour when reporting lines that do not
+ match.
Version 8.11 10-Dec-2010
diff --git a/RunGrepTest b/RunGrepTest
index 0b310af..26ad6a1 100755
--- a/RunGrepTest
+++ b/RunGrepTest
@@ -10,19 +10,24 @@ export LC_ALL
pcregrep=`pwd`/pcregrep
-echo " "
-echo "Testing pcregrep"
-$pcregrep -V
-
valgrind=
while [ $# -gt 0 ] ; do
case $1 in
valgrind) valgrind="valgrind -q --leak-check=no";;
- *) echo "Unknown argument $1"; exit 1;;
+ *) echo "RunGrepTest: Unknown argument $1"; exit 1;;
esac
shift
done
+echo " "
+if [ "$valgrind" = "" ] ; then
+ echo "Testing pcregrep"
+else
+ echo "Testing pcregrep using valgrind"
+fi
+
+$pcregrep -V
+
cf="diff -ub"
# Set up a suitable "diff" command for comparison. Some systems have a diff
@@ -327,6 +332,10 @@ echo "---------------------------- Test 68 ------------------------------" >>tes
(cd $srcdir; $valgrind $pcregrep --only-matching=2 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtry
echo "RC=$?" >>testtry
+echo "---------------------------- Test 69 -----------------------------" >>testtry
+(cd $srcdir; $valgrind $pcregrep -vn --colour=always pattern ./testdata/grepinputx) >>testtry
+echo "RC=$?" >>testtry
+
# Now compare the results.
$cf $srcdir/testdata/grepoutput testtry
diff --git a/pcregrep.c b/pcregrep.c
index 26a0222..a28250e 100644
--- a/pcregrep.c
+++ b/pcregrep.c
@@ -1355,9 +1355,9 @@ while (ptr < endptr)
#endif
/* We have to split the line(s) up if colouring, and search for further
- matches. */
+ matches, but not of course if the line is a non-match. */
- if (do_colour)
+ if (do_colour && !invert)
{
int last_offset = 0;
FWRITE(ptr, 1, offsets[0], stdout);
diff --git a/testdata/grepoutput b/testdata/grepoutput
index b91a3da..e6bb45c 100644
--- a/testdata/grepoutput
+++ b/testdata/grepoutput
@@ -538,3 +538,46 @@ RC=0
---------------------------- Test 68 ------------------------------
pear
RC=0
+---------------------------- Test 69 -----------------------------
+1:This is a second file of input for the pcregrep tests.
+2:
+4:
+5:Pattern
+6:That time it was on a line by itself.
+7:
+8:To pat or not to pat, that is the question.
+9:
+10:complete pair
+11:of lines
+12:
+13:That was a complete pair
+14:of lines all by themselves.
+15:
+16:complete pair
+17:of lines
+18:
+19:And there they were again, to check line numbers.
+20:
+21:one
+22:two
+23:three
+24:four
+25:five
+26:six
+27:seven
+28:eight
+29:nine
+30:ten
+31:eleven
+32:twelve
+33:thirteen
+34:fourteen
+35:fifteen
+36:sixteen
+37:seventeen
+38:eighteen
+39:nineteen
+40:twenty
+41:
+43:This is the last line of this file.
+RC=0