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:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 18:01:29 2024 UTC