Skip to content

Commit

Permalink
Optional route arguments will return null instead of empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
damianopetrungaro committed Aug 4, 2017
1 parent a801608 commit dab03cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/Matchable/MatchableRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ private function matchByRegex(string $pattern, string $path): array
}

foreach ($matches as $k => $match) {
if (is_int($k)) {
$match = array_shift($match);
if (is_int($k) || empty($match)) {
unset($matches[$k]);
continue;
}
$matches[$k] = array_shift($match);
$matches[$k] = $match;
}

return [$isPatternMatched, $matches];
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Matchable/RequestMatchableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public function matchDataProvider()
['/users/{id::\d+}', ['POST', 'GET'], 'DELETE', '/users/string', false, false, []],
['/users/{id::\d+}', ['DELETE'], 'DELETE', '/users/1', true, true, ['id' => 1]],
['/string[/{id::\d+}]', ['PUT'], 'PUT', '/string/11111111111', true, true, ['id' => '11111111111']],
['/string[/[{id::\d+}]]', ['PUT'], 'PUT', '/string/', true, true, ['id' => '']],
['/string[/[{id::\d+}]]', ['PUT'], 'PUT', '/string/', true, true, []],
['/string[/{id::\d+}]', ['PUT'], 'PUT', '/string/q', false, false, []],
['::/users/(?<attribute>\d+)', ['PUT'], 'PUT', '/users/1221', true, true, ['attribute' => '1221']],
['/sub/[{a}/[{b}/[{c}]]]', ['GET'], 'GET', '/sub/1/', true, true, ['a' => 1, 'b' => '', 'c' => '']],
['/sub/[{a}/[{b}/[{c}]]]', ['GET'], 'GET', '/sub/1/2/', true, true, ['a' => 1, 'b' => 2, 'c' => '']],
['/sub/[{a}/[{b}/[{c}]]]', ['GET'], 'GET', '/sub/1/', true, true, ['a' => 1]],
['/sub/[{a}/[{b}/[{c}]]]', ['GET'], 'GET', '/sub/1/2/', true, true, ['a' => 1, 'b' => 2]],
['/sub/[{a}/[{b}/[{c}]]]', ['GET'], 'GET', '/sub/1/2/3', true, true, ['a' => 1, 'b' => 2, 'c' => 3]],
];
}
Expand Down

0 comments on commit dab03cc

Please sign in to comment.