X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2FMagicWordArray.php;h=5856e21b717d0dd724bc43788fe779f106134d9f;hp=7461191fca0007d689217a1a76b606acb4008db0;hb=802c199d0bd80ff0f4d730c61fd58cbf08a52d8d;hpb=9404f8a589a9eed548da33fbfbcb12d3038e59e0 diff --git a/includes/MagicWordArray.php b/includes/MagicWordArray.php index 7461191fca..5856e21b71 100644 --- a/includes/MagicWordArray.php +++ b/includes/MagicWordArray.php @@ -95,13 +95,22 @@ class MagicWordArray { public function getBaseRegex() { if ( is_null( $this->baseRegex ) ) { $this->baseRegex = [ 0 => '', 1 => '' ]; + $allGroups = []; foreach ( $this->names as $name ) { $magic = MagicWord::get( $name ); $case = intval( $magic->isCaseSensitive() ); foreach ( $magic->getSynonyms() as $i => $syn ) { // Group name must start with a non-digit in PCRE 8.34+ $it = strtr( $i, '0123456789', 'abcdefghij' ); - $group = "(?P<{$it}_{$name}>" . preg_quote( $syn, '/' ) . ')'; + $groupName = $it . '_' . $name; + $group = '(?P<' . $groupName . '>' . preg_quote( $syn, '/' ) . ')'; + // look for same group names to avoid same named subpatterns in the regex + if ( isset( $allGroups[$groupName] ) ) { + throw new MWException( + __METHOD__ . ': duplicate internal name in magic word array: ' . $name + ); + } + $allGroups[$groupName] = true; if ( $this->baseRegex[$case] === '' ) { $this->baseRegex[$case] = $group; } else {