php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71036 When using /x modifier, a "/" in a regex comment is seen as a regex delimiter
Submitted: 2015-12-05 01:26 UTC Modified: 2016-06-17 14:53 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: cmanley at xs4all dot nl Assigned:
Status: Verified Package: PCRE related
PHP Version: 5.6.14-0+deb8u1 OS: Debian 8.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cmanley at xs4all dot nl
New email:
PHP Version: OS:

 

 [2015-12-05 01:26 UTC] cmanley at xs4all dot nl
Description:
------------
The documentation for the x (PCRE_EXTENDED) modifier states:
"characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored"

Yet this is not the case in my test example:
The "/" in the regex comment "# firstname/alias" is seen as a regex delimiter.

Test script:
---------------
<?php
$fullname = 'Joe Blow';
if (preg_match('/^
	(\S+)	# firstname/alias
	\s+
	\S+	# surname
$/x', $fullname, $matches)) {
	print $matches[1] . "\n";
}


Expected result:
----------------
Joe

Actual result:
--------------
PHP Warning:  preg_match(): Unknown modifier 'a' in /home/cmanley/t.php on line 8

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-05 01:28 UTC] cmanley at xs4all dot nl
-PHP Version: 5.6.16 +PHP Version: 5.6.14-0+deb8u1
 [2015-12-05 01:28 UTC] cmanley at xs4all dot nl
.
 [2015-12-05 01:55 UTC] requinix@php.net
-Status: Open +Status: Verified
 [2016-06-17 14:53 UTC] cmb@php.net
For reference: <https://3v4l.org/jh4EJ>.

There's obviously no provision for PCRE_EXTENDED comments in
place[1]. To cater to that, the ending delimiter would have to be
searched from the end of the regex string to be able to get the
modifiers first, and after that a second run would be required to
check that the delimiter is not used anywhere else in the regex
where it is not allowed.

Not sure if it's worth the trouble; maybe we should just change
the documentation accordingly?

[1] <https://github.com/php/php-src/blob/php-7.0.7/ext/pcre/php_pcre.c#L351-L391>
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 23 15:01:31 2019 UTC