php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62427 PCRE invalid "\k" sequence does not cause warning or error
Submitted: 2012-06-27 01:22 UTC Modified: 2012-06-28 01:26 UTC
From: danielklein at airpost dot net Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.4.4 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: danielklein at airpost dot net
New email:
PHP Version: OS:

 

 [2012-06-27 01:22 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-27 03:13 UTC] rasmus@php.net
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
 [2012-06-27 13:16 UTC] felipe@php.net
-Status: Open +Status: Not a bug
 [2012-06-27 13:16 UTC] felipe@php.net
Not a PHP bug. The error depends on the PCRE library version.

$ pcretest 
PCRE version 8.02 2010-03-19

  re> /\k/
data> a
No match
  re> /\g/
Failed: a numbered reference must not be zero at offset 1
 [2012-06-28 01:26 UTC] danielklein at airpost dot net
I see... PHP 5.4.4 is using PCRE 8.12 (according to my phpinfo();) This particular bug was fixed in PCRE 8.13 :( Missed it by >that< much...
http://pcre.org/changelog.txt - Search for \k

Can PHP be updated to use the latest PCRE?

P.S. I thought you were only allowed to report issues against the current version of PHP? PCRE 8.02 was included in PHP 5.3.3 :p

P.P.S. The documentation is out of date on the following page:
http://www.php.net/manual/en/pcre.installation.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 05:01:27 2025 UTC