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

View File

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