Bug #81185 [Opn->Fbk]: preg_match fails to match while it seemingly should

From: Date: Mon, 21 Jun 2021 11:42:38 +0000
Subject: Bug #81185 [Opn->Fbk]: preg_match fails to match while it seemingly should
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234571@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81185&edit=1

 ID:                 81185
 Updated by:         danack@php.net
 Reported by:        hans at reachdigital dot nl
 Summary:            preg_match fails to match while it seemingly should
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            PCRE related
 Operating System:   macOS Big Sur
 PHP Version:        7.4.20
 Block user comment: N
 Private report:     N

 New Comment:

I don't get the results you seem to have: https://3v4l.org/Xl4DM

Please can you test setting ini_set("pcre.jit", "0") and see if that makes a
difference?


Previous Comments:
------------------------------------------------------------------------
[2021-06-21 11:35:03] hans at reachdigital dot nl

Description:
------------
While debugging an issue (within Magento), I stumbled upon a case where preg_match() is giving an
unexpected result compared to previous PHP versions.

In our case a given pattern is matching two particular strings on older PHP versions, but fails to
match one of them in PHP 7.4.16 (as well as PHP 8.0.6)

Please refer to the test script I've added, which when run with PHP 7.4.16 indicates that the
pattern matches both strings, but when run with PHP 7.4.20 indicates that only one string matches.

Interestingly, putting something like '.+' at the beginning of the pattern makes it work
as expected again

Test script:
---------------
$pattern = "#/(?<moduleName>[^/]+)/layout/[^/]*\.xml$#i";
$res1 = preg_match($pattern,           
"/Users/nickdekleijn/Sites/project-12gobiking-m2/vendor/magento/theme-adminhtml-backend/Magento_Backend/layout/default.xml",
$matches);
$res2 = preg_match($pattern,
"/Users/wimvanderputten/Documents/gob/project-12gobiking-m2/vendor/magento/theme-adminhtml-backend/Magento_Backend/layout/default.xml",
$matches);
var_dump($res1);
var_dump($res2);

Expected result:
----------------
int(1)
int(1)

Actual result:
--------------
int(0)
int(1)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81185&edit=1


Thread (7 messages)

« previous php.bugs (#234571) next »