Bug #81185 [NEW]: preg_match fails to match while it seemingly should
From: hans at reachdigital dot nl
Operating system: macOS Big Sur
PHP version: 7.4.20
Package: PCRE related
Bug Type: Bug
Bug description:preg_match fails to match while it seemingly should
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 bug report at https://bugs.php.net/bug.php?id=81185&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81185&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81185&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81185&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81185&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81185&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81185&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81185&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81185&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81185&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81185&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81185&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81185&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81185&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81185&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81185&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81185&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81185&r=mysqlcfg
Thread (7 messages)
- hans at reachdigital dot nl