Bug #62427 [Opn]: PCRE invalid "\k" sequence does not cause warning or error
| From: | rasmus@php.net | Date: | Wed, 27 Jun 2012 03:13:14 +0000 |
| Subject: | Bug #62427 [Opn]: PCRE invalid "\k" sequence does not cause warning or error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-171562@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62427&edit=1
ID: 62427
Updated by: rasmus@php.net
Reported by: danielklein at airpost dot net
Summary: PCRE invalid "\k" sequence does not cause warning or
error
Status: Open
Type: Bug
Package: PCRE related
PHP Version: 5.4.4
Block user comment: N
Private report: N
New Comment:
For reference, the command pcretest tool that comes with PCRE-8.30 gives this:
re> /\k/
Failed: \k is not followed by a braced, angle-bracketed, or quoted name at offset
2
re> /\g/
Failed: a numbered reference must not be zero at offset 1
Previous Comments:
------------------------------------------------------------------------
[2012-06-27 01:22:24] danielklein at airpost dot net
Description:
------------
The "\k" escape must be followed by 'name', <name> or {name}. A PCRE regex
that contains "\k" without the properly quoted name will compile without an error and will
always fail as "\k" can never (as far as I know) match anything in the subject string. It
is almost identical to "\g", except "\g" also allows "\gn",
"\g{n}" or "\g{-n}" where "n" is any positive decimal number.
I have been unable to test PCRE directly (i.e. via the command line, not through PHP) as I
can't compile it on my computer. I have looked through the source code and the test results,
and from that it seems to be working correctly. Although I'm not 100% sure, I think this bug is
specific to PHP.
Test script:
---------------
<?php
var_dump(preg_match('/\k/', 'foo')); // Missing named reference
var_dump(preg_match('/\g/', 'foo')); // Missing named or numbered reference
?>
Expected result:
----------------
Warning: preg_match(): Compilation failed: **something about name missing in \k back-reference** at
offset 1 in test.php on line 3
bool(false)
Warning: preg_match(): Compilation failed: a numbered reference must not be zero at offset 1 in
test.php on line 3
bool(false)
Actual result:
--------------
int(0)
Warning: preg_match(): Compilation failed: a numbered reference must not be zero at offset 1 in
test.php on line 3
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62427&edit=1