Skip to content

Commit

Permalink
Fix issue in Routing where a url with 2 params which were given equal…
Browse files Browse the repository at this point in the history
… values would not be recognized.
  • Loading branch information
Robin de Graaf committed Apr 6, 2017
1 parent 2d54c46 commit 162a210
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Parable PHP Framework Changelog

### 0.9.6

__Bugfixes__
- `\Parable\Routing\Route` now injects parameters correctly. This fixes a rare bug where a url with `/a/{id}/b/{name}` would fail if both `$id` and `$name` had the same value.

### 0.9.5

__Changes__
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class App
protected $database;

/** @var string */
protected $version = '0.9.5';
protected $version = '0.9.6';

public function __construct(
\Parable\Filesystem\Path $path,
Expand Down
10 changes: 6 additions & 4 deletions src/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ protected function checkParameterValueType($name, $value)
protected function injectParameters($url)
{
$urlParts = explode('/', $url);
$parameters = array_flip($this->values);
foreach ($urlParts as &$part) {
if (isset($parameters[$part])) {
$part = '{' . ltrim($parameters[$part], '{}') . '}';

foreach ($this->values as $key => $value) {
$foundKey = array_search($value, $urlParts);
if ($foundKey !== false) {
$urlParts[$foundKey] = '{' . ltrim($key, '{}') . '}';
}
}
return implode('/', $urlParts);
Expand Down Expand Up @@ -201,6 +202,7 @@ public function matchWithParameters($url)
return false;
}
$correctedUrl = $this->injectParameters($url);

if ($this->matchDirectly($correctedUrl)) {
return true;
}
Expand Down

0 comments on commit 162a210

Please sign in to comment.