Bug #77827 [Ver->Csd]: preg_match does not ignore \r in regex flags
| From: | cmb@php.net | Date: | Sun, 31 Mar 2019 11:37:39 +0000 |
| Subject: | Bug #77827 [Ver->Csd]: preg_match does not ignore \r in regex flags | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220269@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77827&edit=1
ID: 77827
Updated by: cmb@php.net
Reported by: peehaa@php.net
Summary: preg_match does not ignore \r in regex flags
-Status: Verified
+Status: Closed
Type: Bug
Package: PCRE related
Operating System: Windows
PHP Version: 7.3.3
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=88460c017a06ce8865f1adcc8f70e511cf776e06
Log: Fix #77827: preg_match does not ignore \r in regex flags
Previous Comments:
------------------------------------------------------------------------
[2019-03-30 20:44:56] peehaa@php.net
Awesome! Thanks for digging into it and confirming I am not going entirely crazy yet.
------------------------------------------------------------------------
[2019-03-30 20:32:50] requinix@php.net
Found it. The problem is the line ending in the flags part: PHP will ignore \n but not \r, then
complain about it as an invalid flag.
https://github.com/php/php-src/blob/PHP-7.3.3/ext/pcre/php_pcre.c#L696
When I tested, I had created the file with LF line endings.
What's more, the error message is confusing because it says this (with Xdebug) in cmd, where
the \r causes a carriage return and so overwrites the rest of the message:
string(16) "10.32 2018-09-10"
' in C:\Users\xxxxxx\t.php on line 17er '
Call Stack:
0.4049 397800 1. {main}() C:\Users\xxxxxx\t.php:0
0.4051 397832 2. preg_match() C:\Users\xxxxxx\t.php:17
C:\Users\xxxxxx\t.php:17:
bool(false)
C:\Users\xxxxxx\t.php:18:
int(1)
The error message was actually
Warning: preg_match(): Unknown modifier ''
with an \r between the apostrophes.
------------------------------------------------------------------------
[2019-03-30 20:16:47] peehaa@php.net
Nope. Same result. When I check a hex dump of my file I also do not see anything strange at first
sight.
------------------------------------------------------------------------
[2019-03-30 19:43:03] requinix@php.net
Works for my 7.3.3 on Windows. Does it work if you copy/paste the code from this bug report? Is
there maybe a stray unprintable character in your file?
------------------------------------------------------------------------
[2019-03-30 19:37:24] peehaa@php.net
Weirdly enough when I use a single line pattern it starts working:
<?php
$pattern =
'~^(?:(?:(?P<function>function)\s*\(\s*(?:(?P<table1>.+)(?:\.))?(?P<column1>[^
]+)\s*\))|(?:(?P<table2>.+)(?:\.))?(?P<column2>[^
]+))(?:\s+as\s+(?P<alias>.+))?$~ix';
var_dump(PCRE_VERSION);
var_dump(preg_match($pattern, 'id'));
var_dump(preg_last_error());
-----
string(16) "10.32 2018-09-10"
int(1)
int(0)
Am I doing something wrong here in combination with the platform I am on somehow?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=77827
--
Edit this bug report at https://bugs.php.net/bug.php?id=77827&edit=1