Skip to content

Commit

Permalink
Merge pull request #333 from switchplane-tom/feature/fix-routes-with-…
Browse files Browse the repository at this point in the history
…multiple-wildcards

Fix routes with multiple wildcards
  • Loading branch information
philipobenito authored Sep 28, 2024
2 parents b56a818 + 0b989c4 commit 2be0aa8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getPath(?array $replacements = null): string
$toReplace = [];

foreach ($replacements as $wildcard => $actual) {
$toReplace['/{' . preg_quote($wildcard, '/') . '(:.*)?}/'] = $actual;
$toReplace['/{' . preg_quote($wildcard, '/') . '(:.*)?}/U'] = $actual;
}

$segments = [];
Expand Down
9 changes: 5 additions & 4 deletions tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,16 @@ public function process(

public function testGetPathReplacesWildcards(): void
{
$route = new Route('GET', '/a/{wildcard}/and/{wildcardWithMatcher:uuid}', static function () {
$route = new Route('GET', '/a/{wildcard}/and/{wildcardWithMatcher:uuid}/and/{wildcardWithMatcherAgain:uuid}', static function () {
});

$path = $route->getPath([
'wildcard' => 'replaced-wildcard',
'wildcardWithMatcher' => 'replaced-wildcard-with-matcher',
'wildcard' => 'replaced-wildcard',
'wildcardWithMatcher' => 'replaced-wildcard-with-matcher',
'wildcardWithMatcherAgain' => 'replaced-wildcard-with-matcher-again',
]);

$this->assertSame('/a/replaced-wildcard/and/replaced-wildcard-with-matcher', $path);
$this->assertSame('/a/replaced-wildcard/and/replaced-wildcard-with-matcher/and/replaced-wildcard-with-matcher-again', $path);
}

public function testGetPathReplacesOptional(): void
Expand Down

0 comments on commit 2be0aa8

Please sign in to comment.