Skip to content

Commit

Permalink
Small bugfix in routing
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin de Graaf committed Apr 15, 2019
1 parent faff249 commit e247248
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Parable Routing

## 0.2.3

_Bugfix_

- Small fix in `Router`, where while replacing parameters in a url we're matching would not check if the original url part was actually a parameter.

## 0.2.2

_Changes_
Expand Down
4 changes: 4 additions & 0 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ protected function matchParametered(string $httpMethod, string $urlToMatch): ?Ro
foreach ($providedValues as $key => $value) {
$parameter = $explodedRouteUrl[$key];

if (strpos($parameter, '{') === false) {
continue;
}

$valuesWithParameterAsKey[trim($parameter, '{}')] = $value;

$explodedUrlToMatch[$key] = $parameter;
Expand Down
14 changes: 14 additions & 0 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,18 @@ public function dpSimpleUrls(): array
['/simple/'],
];
}

public function testSimilarUrlsDoNotConflictAndParametersAreReplacedCorrectly()
{
$this->router->add(['GET'], 'route1', 'route1/{param}', function () {});
$this->router->add(['GET'], 'route2', 'route2/{param}', function () {});

$matched = $this->router->match('GET', 'route1/test');

self::assertSame('route1', $matched->getName());

$matched = $this->router->match('GET', 'route2/test');

self::assertSame('route2', $matched->getName());
}
}

0 comments on commit e247248

Please sign in to comment.