Template Routes do not match slash prefix variables that contain slashes as the non-first character

This commit is contained in:
PJ Dietz 2015-05-25 10:17:42 -04:00
parent 753e9ff33a
commit 139e3c43da
2 changed files with 12 additions and 6 deletions

View File

@ -125,6 +125,9 @@ class TemplateRoute extends Route
// characters to allow in the match. // characters to allow in the match.
$operator = $name[0]; $operator = $name[0];
// Read the last character as the modifier.
$explosion = (substr($name, -1, 1) === "*");
switch ($operator) { switch ($operator) {
case "+": case "+":
$name = substr($name, 1); $name = substr($name, 1);
@ -138,15 +141,17 @@ class TemplateRoute extends Route
break; break;
case "/": case "/":
$name = substr($name, 1); $name = substr($name, 1);
$pattern = '[0-9a-zA-Z\-._\~%,\/]*'; // Unreserved + "," and "/"
$prefix = "\\/"; $prefix = "\\/";
$delimiter = "\\/"; $delimiter = "\\/";
$explodeDelimiter = "/"; if ($explosion) {
$pattern = '[0-9a-zA-Z\-._\~%,\/]*'; // Unreserved + "," and "/"
$explodeDelimiter = "/";
}
break; break;
} }
// Explosion // Explosion
if (substr($name, -1, 1) === "*") { if ($explosion) {
$name = substr($name, 0, -1); $name = substr($name, 0, -1);
if ($pattern === self::RE_UNRESERVED) { if ($pattern === self::RE_UNRESERVED) {
$pattern = '[0-9a-zA-Z\-._\~%,]*'; // Unreserved + "," $pattern = '[0-9a-zA-Z\-._\~%,]*'; // Unreserved + ","

View File

@ -78,9 +78,10 @@ class TemplateRouteTest extends \PHPUnit_Framework_TestCase
public function nonMatchingTargetProvider() public function nonMatchingTargetProvider()
{ {
return [ return [
["/foo/{var}", "/bar/12", false, "Mismatch before first template expression"], ["/foo/{var}", "/bar/12", "Mismatch before first template expression"],
["/foo/{foo}/bar/{bar}", "/foo/12/13", false, "Mismatch after first template expression"], ["/foo/{foo}/bar/{bar}", "/foo/12/13", "Mismatch after first template expression"],
["/hello/{hello}", "/hello/Hello%20World!", false, "Requires + operator to match reserver characters"] ["/hello/{hello}", "/hello/Hello%20World!", "Requires + operator to match reserver characters"],
["{/var}", "/bar/12", "Path contains more segements than template"],
]; ];
} }