Revision: 629
http://vcs.pcre.org/viewvc?view=rev&revision=629
Author: ph10
Date: 2011-07-22 10:18:11 +0100 (Fri, 22 Jul 2011)
Log Message:
-----------
Fix isolated \k bug.
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/pcre_compile.c
code/trunk/pcre_internal.h
code/trunk/pcreposix.c
code/trunk/testdata/testinput2
code/trunk/testdata/testoutput2
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2011-07-20 18:03:20 UTC (rev 628)
+++ code/trunk/ChangeLog 2011-07-22 09:18:11 UTC (rev 629)
@@ -158,6 +158,10 @@
29. Added the '=' option to pcretest to check the setting of unused capturing
slots at the end of the pattern, which are documented as being -1, but are
not included in the return count.
+
+30. If \k was not followed by a braced, angle-bracketed, or quoted name, PCRE
+ compiled something random. Now it gives a compile-time error (as does
+ Perl).
Version 8.12 15-Jan-2011
Modified: code/trunk/pcre_compile.c
===================================================================
--- code/trunk/pcre_compile.c 2011-07-20 18:03:20 UTC (rev 628)
+++ code/trunk/pcre_compile.c 2011-07-22 09:18:11 UTC (rev 629)
@@ -409,6 +409,7 @@
"(*MARK) must have an argument\0"
"this version of PCRE is not compiled with PCRE_UCP support\0"
"\\c must be followed by an ASCII character\0"
+ "\\k is not followed by a braced, angle-bracketed, or quoted name\0"
;
/* Table to identify digits and hex digits. This is used when compiling
@@ -6125,17 +6126,22 @@
}
/* \k<name> or \k'name' is a back reference by name (Perl syntax).
- We also support \k{name} (.NET syntax) */
+ We also support \k{name} (.NET syntax). */
- if (-c == ESC_k && (ptr[1] == CHAR_LESS_THAN_SIGN ||
- ptr[1] == CHAR_APOSTROPHE || ptr[1] == CHAR_LEFT_CURLY_BRACKET))
+ if (-c == ESC_k)
{
+ if ((ptr[1] != CHAR_LESS_THAN_SIGN &&
+ ptr[1] != CHAR_APOSTROPHE && ptr[1] != CHAR_LEFT_CURLY_BRACKET))
+ {
+ *errorcodeptr = ERR69;
+ break;
+ }
is_recurse = FALSE;
terminator = (*(++ptr) == CHAR_LESS_THAN_SIGN)?
CHAR_GREATER_THAN_SIGN : (*ptr == CHAR_APOSTROPHE)?
CHAR_APOSTROPHE : CHAR_RIGHT_CURLY_BRACKET;
goto NAMED_REF_OR_RECURSE;
- }
+ }
/* Back references are handled specially; must disable firstbyte if
not set to cope with cases like (?=(\w+))\1: which would otherwise set
Modified: code/trunk/pcre_internal.h
===================================================================
--- code/trunk/pcre_internal.h 2011-07-20 18:03:20 UTC (rev 628)
+++ code/trunk/pcre_internal.h 2011-07-22 09:18:11 UTC (rev 629)
@@ -1660,7 +1660,7 @@
ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39,
ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49,
ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59,
- ERR60, ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68,
+ ERR60, ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69,
ERRCOUNT };
/* The real format of the start of the pcre block; the index of names and the
Modified: code/trunk/pcreposix.c
===================================================================
--- code/trunk/pcreposix.c 2011-07-20 18:03:20 UTC (rev 628)
+++ code/trunk/pcreposix.c 2011-07-22 09:18:11 UTC (rev 629)
@@ -152,6 +152,7 @@
REG_BADPAT, /* (*MARK) must have an argument */
REG_INVARG, /* this version of PCRE is not compiled with PCRE_UCP support */
REG_BADPAT, /* \c must be followed by an ASCII character */
+ REG_BADPAT, /* \k is not followed by a braced, angle-bracketed, or quoted name */
};
/* Table of texts corresponding to POSIX error codes */
Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2 2011-07-20 18:03:20 UTC (rev 628)
+++ code/trunk/testdata/testinput2 2011-07-22 09:18:11 UTC (rev 629)
@@ -2497,6 +2497,10 @@
/\k{}/
+/\k/
+
+/\kabc/
+
/(?P=)/
/(?P>)/
Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2 2011-07-20 18:03:20 UTC (rev 628)
+++ code/trunk/testdata/testoutput2 2011-07-22 09:18:11 UTC (rev 629)
@@ -9246,6 +9246,12 @@
/\k{}/
Failed: subpattern name expected at offset 3
+/\k/
+Failed: \k is not followed by a braced, angle-bracketed, or quoted name at offset 2
+
+/\kabc/
+Failed: \k is not followed by a braced, angle-bracketed, or quoted name at offset 5
+
/(?P=)/
Failed: subpattern name expected at offset 4