From 53dd6b5840f70c3eb151ba47e4d47c433f4cc08c Mon Sep 17 00:00:00 2001 From: Tom Kay Date: Fri, 4 Jan 2019 17:41:17 +0000 Subject: [PATCH] fix meaning of @all in routes --- src/Routing/Constraint.php | 4 ++-- tests/Routing/ConstraintTest.php | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Routing/Constraint.php b/src/Routing/Constraint.php index fa42339..ef7c015 100644 --- a/src/Routing/Constraint.php +++ b/src/Routing/Constraint.php @@ -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); } diff --git a/tests/Routing/ConstraintTest.php b/tests/Routing/ConstraintTest.php index a5339c7..a8b1c55 100644 --- a/tests/Routing/ConstraintTest.php +++ b/tests/Routing/ConstraintTest.php @@ -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')); @@ -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);