Skip to content

Commit

Permalink
fix meaning of @ALL in routes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomK committed Jan 4, 2019
1 parent 508f20d commit 53dd6b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Routing/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ protected function _convertPathToRegex($path, $type)
"/{" . "$idPat\@alphanum}/" => "(?P<$1>\w+)",
"/{" . "$idPat\@alnum}/" => "(?P<$1>\w+)",
"/{" . "$idPat\@alpha}/" => "(?P<$1>[a-zA-Z]+)",
"/{" . "$idPat\@all}/" => "(?P<$1>[^\/]+)",
"/{" . "$idPat\@all}/" => "(?P<$1>.+)",
"/{" . "$idPat\@num}/" => "(?P<$1>\d+)",
"/{" . "$idPat}/" => "(?P<$1>.+)",
"/{" . "$idPat}/" => "(?P<$1>[^\/]+)",
];
$path = preg_replace(array_keys($repl), array_values($repl), $path);
}
Expand Down
17 changes: 12 additions & 5 deletions tests/Routing/ConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ public function testConstraints()

public function testRouteData()
{
$request = Request::create('http://www.test.com:8080/one/two/three/4/5/s1x/s3^eN!/uncaptured', 'POST');
$request = Request::create(
'http://www.test.com:8080/one/two/three/4/5/s1x/s3^eN!/all/remain/path/end/finished',
'POST'
);
$ctx = new Context($request);

$this->assertTrue(
HttpConstraint::path('/{one}/{two@alpha}/{three}/{four@num}/{five@alphanum}/{six@alphanum}/{seven@all}')->match(
$ctx
)
HttpConstraint::path(
'/{one}/{two@alpha}/{three}/{four@num}/{five@alphanum}/{six@alphanum}/{seven}/{remain@all}/end'
)->match($ctx)
);
$this->assertEquals("one", $ctx->routeData()->get('one'));
$this->assertEquals("two", $ctx->routeData()->get('two'));
Expand All @@ -77,7 +80,11 @@ public function testRouteData()
$this->assertEquals("5", $ctx->routeData()->get('five'));
$this->assertEquals("s1x", $ctx->routeData()->get('six'));
$this->assertEquals("s3^eN!", $ctx->routeData()->get('seven'));
$this->assertEquals('/one/two/three/4/5/s1x/s3^eN!', $ctx->meta()->get(Constraint::META_ROUTED_PATH));
$this->assertEquals("all/remain/path", $ctx->routeData()->get('remain'));
$this->assertEquals(
'/one/two/three/4/5/s1x/s3^eN!/all/remain/path/end',
$ctx->meta()->get(Constraint::META_ROUTED_PATH)
);

$request = Request::create('http://www.test.com:8080/INV123');
$ctx = new Context($request);
Expand Down

0 comments on commit 53dd6b5

Please sign in to comment.