Skip to content

Commit c203b59

Browse files
committed
fix(Router): preserve $0 reference, document behavior, and add changelog entry
1 parent 86814ac commit c203b59

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎docs/changelogs/v4.7.7.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Release Date: Unreleased
2929
- **HTTP:** Fixed a bug where query-string based routing truncated additional query parameters in `SiteURIFactory::parseRequestURI()` due to incorrect array index access.
3030
- **HTTP:** Fixed a bug where `UploadedFile::move()` and `UploadedFile::store()` on Windows could store a file under a different name than `getName()` reported, or write its contents to an NTFS alternate data stream. Filenames ending in a period or space or containing a colon are now rejected, including explicitly supplied names.
3131
- **Images:** Fixed a bug in `ImageMagickHandler::save()` where saving without an extension or with an unsupported extension threw an `ImagickException` instead of falling back to the image's format.
32+
- **Router:** Fixed a bug where `Router::replaceBackReferences()` failed to match and replace multi-digit back-references (such as `$10` or higher) when `Routing::$multipleSegmentsOneParam` was enabled.
3233
- **Routing:** Fixed a bug where redirect routes containing the `{locale}` placeholder were not recognized as redirects and did not replace `{locale}` in the redirect target.
3334
- **Security:** Fixed a bug where `Security::__construct()` threw a `TypeError` when the CSRF cookie was an array, causing an HTTP 500 response for affected requests.
3435
- **Security:** Fixed a bug in `strip_image_tags()` where an invalid PCRE character class caused attribute injection and improper quote handling, and ensured tags without `src` are stripped.

‎docs/incoming/routing.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ $routes->get('product/(:any)', 'Catalog::productLookup/$1');
10221022
will match **product/123**, **product/123/456**, **product/123/456/789** and so on. And if the URI is **product/123/456**, `123/456` will be passed to the first parameter of the `Catalog::productLookup()` method.
10231023

10241024
!!! note "Note"
1025-
When this option is enabled, consecutive digits in back-references (such as `$10`) are treated as a single reference rather than `$1` followed by `0`. If a back-reference does not have a matching captured group, it resolves to an empty string (`''`).
1025+
When this option is enabled, consecutive digits in back-references (such as `$10`) are treated as a single reference rather than `$1` followed by `0`. The `$0` back-reference resolves to the entire matched path. If a back-reference does not have a matching captured group, it resolves to an empty string (`''`).
10261026

10271027
## Auto Routing (Improved)
10281028

‎system/Router/Router.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ protected function checkRoutes(string $uri): bool
569569
*/
570570
private function replaceBackReferences(string $input, array $matches): string
571571
{
572-
$pattern = '/\$([1-9][0-9]*)/u';
572+
$pattern = '/\$(0|[1-9][0-9]*)/u';
573573

574574
return preg_replace_callback(
575575
$pattern,

‎tests/system/Router/RouterTest.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,13 @@ public static function provideMultipleSegmentsParamTrueWithManyPlaceholders(): i
10951095
'product/foo',
10961096
[''],
10971097
];
1098+
1099+
yield 'reference $0 resolves to entire matched path' => [
1100+
$nineSegments,
1101+
'Catalog::lookup/$0/$1',
1102+
'a/b/c/d/e/f/g/h/i',
1103+
['a/b/c/d/e/f/g/h/i', 'a'],
1104+
];
10981105
}
10991106

11001107
public function testLogsRouteAttributeInstantiationFailureWithContext(): void

0 commit comments

Comments
 (0)