Bug #80645 [NEW]: PHPs behavior of empty string matching is incorrect

From: Date: Tue, 19 Jan 2021 13:03:55 +0000
Subject: Bug #80645 [NEW]: PHPs behavior of empty string matching is incorrect
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231635@lists.php.net to get a copy of this message
From: firas dot dib at gmail dot com Operating system: n/a PHP version: 8.0.1 Package: PCRE related Bug Type: Bug Bug description:PHPs behavior of empty string matching is incorrect Description: ------------ PHP is currently not matching empty strings in a perl compatible way. If we use the following regex: /(?<=(\G.{2}))(?!$)/g and the following string: 123456789 We would get the following results in PCRE1 and PHP (both PHP <7.3 and >=7.3): "12", "45", "78" However, in PCRE2 (and Perl), we would get: "12", "34", "56", "78" This can be verified by using pcre2test and perltest that is bundled with PCRE2. The changelog for PCRE2 10.32 states the following: 21. In both pcre2test and pcre2_substitute(), with global matching, a pattern that matched an empty string, but never at the starting match offset, was not handled in a Perl-compatible way. The pattern /(<?=\G.)/ is an example of such a pattern. Because \G is in a lookbehind assertion, there has to be a "bumpalong" before there can be a match. The automatic "advance by one character after an empty string match" rule is therefore inappropriate. A more complicated algorithm has now been implemented. I am not sure if this behavior is intentional or not, but figured I'd highlight it to you. Best, Firas Test script: --------------- <?php preg_match_all("/(?<=(\G.{2}))(?!$)/", "123456789", $matches); var_dump($matches); ?> Expected result: ---------------- "12", "34", "56", "78" Actual result: -------------- "12", "45", "78" -- Edit bug report at https://bugs.php.net/bug.php?id=80645&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80645&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80645&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80645&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80645&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80645&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80645&r=support Expected behavior: https://bugs.php.net/fix.php?id=80645&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80645&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80645&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80645&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80645&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80645&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80645&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80645&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80645&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80645&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80645&r=mysqlcfg

« previous php.bugs (#231635) next »