Bug #79028 [NEW]: Several same-name subpatterns in distinct piped alternatives should be allowed
| From: | php4fan at gmail dot com | Date: | Tue, 24 Dec 2019 17:18:05 +0000 |
| Subject: | Bug #79028 [NEW]: Several same-name subpatterns in distinct piped alternatives should be allowed | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-224521@lists.php.net to get a copy of this message | ||
From: php4fan at gmail dot com
Operating system:
PHP version: 7.2.26
Package: *Regular Expressions
Bug Type: Bug
Bug description:Several same-name subpatterns in distinct piped alternatives should be allowed
Description:
------------
see below test script and expected and observed behavior below.
Maybe this an issue at the level of regular expressions specifications.
As I only use them in PHP, I don't know, so I report it here. Also, it's
so evidently flawed that maybe PHP could implement them correctly anyway
while waiting for the specs to be fixed; not sure about that.
Test script:
---------------
<?php
$content = <<<'HERE'
First match: foo::"XYZ"
Second match: bar--<XYZ>
HERE;
$content=preg_replace_callback('#foo::"(?<sub>[^"]*)"|bar--<(?<sub>[^>]*)>#',
'testReplace', $content);
function testReplace($match) {
print_r($match);
return 'XXX';
}
Expected result:
----------------
Array
(
[0] => foo::"XYZ"
[sub] => XYZ
[1] => XYZ
)
Array
(
[0] => bar--<XYZ>
[1] =>
[sub] => XYZ
[2] => XYZ
)
Actual result:
--------------
Warning: preg_replace_callback(): Compilation failed: two named
subpatterns have the same name
Because the subgroups with the same name appear on two sides of a "|",
there should be no conflict. At most one of the piped patterns (i.e.
either side of the "|") can match, they are mutually exclusive, so there
is no ambiguity possible and it should be a problem that a subgroup
appear in both of them with the same name, as it can only be assigned
once anyway.
--
Edit bug report at https://bugs.php.net/bug.php?id=79028&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79028&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79028&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79028&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79028&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79028&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79028&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79028&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79028&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79028&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79028&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79028&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79028&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79028&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79028&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79028&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79028&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79028&r=mysqlcfg