X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FPathRouter.php;h=eb52d7cd23d9ce415aea7afdaf93b69e1053ba32;hb=e5eb5ac92815340f389048291d71ad9ddb75e690;hp=f24e298a0d24c765faf8e1471dc0607fbfcbb051;hpb=0df3355fba2fb0cfc2ab277036ca4352b9c56375;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/PathRouter.php b/includes/PathRouter.php index f24e298a0d..eb52d7cd23 100644 --- a/includes/PathRouter.php +++ b/includes/PathRouter.php @@ -133,10 +133,8 @@ class PathRouter { // Loop over our options and convert any single value $# restrictions // into an array so we only have to do in_array tests. foreach ( $options as $optionName => $optionData ) { - if ( preg_match( '/^\$\d+$/u', $optionName ) ) { - if ( !is_array( $optionData ) ) { - $options[$optionName] = [ $optionData ]; - } + if ( preg_match( '/^\$\d+$/u', $optionName ) && !is_array( $optionData ) ) { + $options[$optionName] = [ $optionData ]; } } @@ -240,6 +238,28 @@ class PathRouter { // matches are tested first $this->sortByWeight(); + $matches = $this->internalParse( $path ); + if ( is_null( $matches ) ) { + // Try with the normalized path (T100782) + $path = wfRemoveDotSegments( $path ); + $path = preg_replace( '#/+#', '/', $path ); + $matches = $this->internalParse( $path ); + } + + // We know the difference between null (no matches) and + // array() (a match with no data) but our WebRequest caller + // expects array() even when we have no matches so return + // a array() when we have null + return $matches ?? []; + } + + /** + * Match a path against each defined pattern + * + * @param string $path + * @return array|null + */ + protected function internalParse( $path ) { $matches = null; foreach ( $this->patterns as $pattern ) { @@ -248,12 +268,7 @@ class PathRouter { break; } } - - // We know the difference between null (no matches) and - // array() (a match with no data) but our WebRequest caller - // expects array() even when we have no matches so return - // a array() when we have null - return is_null( $matches ) ? [] : $matches; + return $matches; } /**