preg_match missing group names in matches
| Bug #72688 | preg_match missing group names in matches | ||||
|---|---|---|---|---|---|
| Submitted: | 2016-07-27 15:19 UTC | Modified: | 2016-07-27 16:36 UTC | ||
| From: | konrad dot baumgart at moneyhouse dot de | Assigned: | cmb (profile) | ||
| Status: | Closed | Package: | PCRE related | ||
| PHP Version: | 7.0.9 | OS: | Ubuntu 16.04 | ||
| Private report: | No | CVE-ID: | None | ||
[2016-07-27 15:19 UTC] konrad dot baumgart at moneyhouse dot de
Description:
------------
When I create many named groups in pattern like
\(?'group0'foo)|(?'group1'bar)|…\
then the resulting $matches does not show 'group254'.
What was supposed to be in `$matches['group254']` is in `$matches['group255']`, and so on.
the lack repeats every ~255 named groups and the offset is getting worse and worse.
I tested it on php 7 and php 5.5, locally and in online-php-sandbox.
Test script:
---------------
<?php
$pattern = [];
for ($i = 0; $i < 300; $i++) {
$pattern[] = "(?'group{$i}'{$i}$)";
}
$fullPattern = '/' . implode('|', $pattern) . '/uix';
preg_match($fullPattern, '290', $matches);
var_dump(isset($matches['group253']));
var_dump(isset($matches['group254']));
var_dump(isset($matches['group255']));
var_dump($matches['group290']);
var_dump($matches['group291']);
Expected result:
----------------
bool(true)
bool(true)
bool(true)
string(3) "290"
string(0) ""
Actual result:
--------------
bool(true)
bool(false)
bool(true)
string(0) ""
string(3) "290"
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2016-07-27 16:36 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: cmb
[2016-07-27 17:15 UTC] cmb@php.net
-Status: Analyzed +Status: Closed