bug #29626 [Routing] fix trailing slash redirections involving a trailing var (nicolas-grekas)

This PR was merged into the 4.1 branch.

Discussion
----------

[Routing] fix trailing slash redirections involving a trailing var

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29553
| License       | MIT
| Doc PR        | -

The code in `PhpMatcherDumper` is terrible, but the good news is that 4.2 is much better already.
The change in `UrlMatcher` is much more readable and implements the same fixed logic.
The new test case is in `UrlMatcherTest`.

Commits
-------

6433f8a3e9 [Routing] fix trailing slash redirections involving a trailing var
This commit is contained in:
Nicolas Grekas 2018-12-17 11:23:48 +01:00
commit 40a79f750f
18 changed files with 1506 additions and 1430 deletions

View File

@ -112,7 +112,8 @@ EOF;
$code = <<<EOF
{
\$allow = \$allowSchemes = array();
\$pathinfo = rawurldecode(\$rawPathinfo) ?: '/';
\$pathinfo = rawurldecode(\$pathinfo) ?: '/';
\$trimmedPathinfo = rtrim(\$pathinfo, '/') ?: '/';
\$context = \$this->context;
\$requestMethod = \$canonicalMethod = \$context->getMethod();
{$fetchHost}
@ -148,8 +149,8 @@ EOF;
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $pathinfo) {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
} elseif ('/' !== $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/') {
$pathinfo = $trimmedPathinfo === $pathinfo ? $pathinfo.'/' : $trimmedPathinfo;
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
@ -161,13 +162,13 @@ EOF;
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
private function doMatch(string $pathinfo, array &$allow = array(), array &$allowSchemes = array()): array
EOF
.$code."\n return array();\n }";
}
return " public function match(\$rawPathinfo)\n".$code."\n throw \$allow ? new MethodNotAllowedException(array_keys(\$allow)) : new ResourceNotFoundException();\n }";
return " public function match(\$pathinfo)\n".$code."\n throw \$allow ? new MethodNotAllowedException(array_keys(\$allow)) : new ResourceNotFoundException();\n }";
}
/**
@ -304,7 +305,7 @@ EOF
EOF;
}
return sprintf(" switch (\$trimmedPathinfo = '/' !== \$pathinfo && '/' === \$pathinfo[-1] ? substr(\$pathinfo, 0, -1) : \$pathinfo) {\n%s }\n\n", $this->indent($code));
return sprintf(" switch (\$trimmedPathinfo) {\n%s }\n\n", $this->indent($code));
}
/**
@ -408,8 +409,9 @@ EOF;
if ($hasTrailingSlash = '/' !== $regex && '/' === $regex[-1]) {
$regex = substr($regex, 0, -1);
}
$hasTrailingVar = (bool) preg_match('#\{\w+\}/?$#', $route->getPath());
$tree->addRoute($regex, array($name, $regex, $state->vars, $route, $hasTrailingSlash));
$tree->addRoute($regex, array($name, $regex, $state->vars, $route, $hasTrailingSlash, $hasTrailingVar));
}
$code .= $this->compileStaticPrefixCollection($tree, $state);
@ -418,7 +420,7 @@ EOF;
$code .= "\n .')'";
$state->regex .= ')';
}
$rx = ")(?:/?)$}{$modifiers}";
$rx = ")/?$}{$modifiers}";
$code .= "\n .'{$rx}',";
$state->regex .= $rx;
$state->markTail = 0;
@ -438,7 +440,7 @@ EOF;
\$routes = array(
{$this->indent($state->default, 4)} );
list(\$ret, \$vars, \$requiredMethods, \$requiredSchemes, \$hasTrailingSlash) = \$routes[\$m];
list(\$ret, \$vars, \$requiredMethods, \$requiredSchemes, \$hasTrailingSlash, \$hasTrailingVar) = \$routes[\$m];
{$this->compileSwitchDefault(true, $matchHost)}
EOF;
}
@ -493,11 +495,11 @@ EOF;
continue;
}
list($name, $regex, $vars, $route, $hasTrailingSlash) = $route;
list($name, $regex, $vars, $route, $hasTrailingSlash, $hasTrailingVar) = $route;
$compiledRoute = $route->compile();
if ($compiledRoute->getRegex() === $prevRegex) {
$state->switch = substr_replace($state->switch, $this->compileRoute($route, $name, false, $hasTrailingSlash)."\n", -19, 0);
$state->switch = substr_replace($state->switch, $this->compileRoute($route, $name, false, $hasTrailingSlash, $hasTrailingVar)."\n", -19, 0);
continue;
}
@ -516,20 +518,21 @@ EOF;
unset($defaults['_canonical_route']);
}
$state->default .= sprintf(
"%s => array(%s, %s, %s, %s, %s),\n",
"%s => array(%s, %s, %s, %s, %s, %s),\n",
$state->mark,
self::export(array('_route' => $name) + $defaults),
self::export($vars),
self::export(array_flip($route->getMethods()) ?: null),
self::export(array_flip($route->getSchemes()) ?: null),
self::export($hasTrailingSlash)
self::export($hasTrailingSlash),
self::export($hasTrailingVar)
);
} else {
$prevRegex = $compiledRoute->getRegex();
$state->switch .= <<<EOF
case {$state->mark}:
{$this->compileRoute($route, $name, false, $hasTrailingSlash, $vars)}
{$this->compileRoute($route, $name, false, $hasTrailingSlash, $hasTrailingVar, $vars)}
break;
EOF;
@ -544,67 +547,84 @@ EOF;
*/
private function compileSwitchDefault(bool $hasVars, bool $matchHost): string
{
$code = sprintf("
if ('/' !== \$pathinfo) {%s
if (\$hasTrailingSlash !== ('/' === \$pathinfo[-1])) {%s
break;
if ($this->supportsRedirections) {
$code = <<<'EOF'
if ('GET' === $canonicalMethod && (!$requiredMethods || isset($requiredMethods['GET']))) {
return $allow = $allowSchemes = array();
}
}\n",
$hasVars ? "
if ('/' === \$pathinfo[-1]) {
if (preg_match(\$regex, substr(\$pathinfo, 0, -1), \$n) && \$m === (int) \$n['MARK']) {
\$matches = \$n;
} else {
\$hasTrailingSlash = true;
}
}\n" : '',
$this->supportsRedirections ? "
if ((!\$requiredMethods || isset(\$requiredMethods['GET'])) && 'GET' === \$canonicalMethod) {
return \$allow = \$allowSchemes = array();
}" : ''
EOF;
} else {
$code = '';
}
$code .= $hasVars ? '
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
break;
}' : '
break;';
$code = sprintf(<<<'EOF'
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {%s
}
EOF
,
$code
);
if ($hasVars) {
$code .= <<<EOF
$code = <<<'EOF'
foreach (\$vars as \$i => \$v) {
if (isset(\$matches[1 + \$i])) {
\$ret[\$v] = \$matches[1 + \$i];
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
EOF
.$code.<<<'EOF'
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
EOF;
} elseif ($matchHost) {
$code .= <<<EOF
$code .= <<<'EOF'
if (\$requiredHost) {
if ('#' !== \$requiredHost[0] ? \$requiredHost !== \$host : !preg_match(\$requiredHost, \$host, \$hostMatches)) {
if ($requiredHost) {
if ('#' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) {
break;
}
if ('#' === \$requiredHost[0] && \$hostMatches) {
\$hostMatches['_route'] = \$ret['_route'];
\$ret = \$this->mergeDefaults(\$hostMatches, \$ret);
if ('#' === $requiredHost[0] && $hostMatches) {
$hostMatches['_route'] = $ret['_route'];
$ret = $this->mergeDefaults($hostMatches, $ret);
}
}
EOF;
}
$code .= <<<EOF
$code .= <<<'EOF'
\$hasRequiredScheme = !\$requiredSchemes || isset(\$requiredSchemes[\$context->getScheme()]);
if (\$requiredMethods && !isset(\$requiredMethods[\$canonicalMethod]) && !isset(\$requiredMethods[\$requestMethod])) {
if (\$hasRequiredScheme) {
\$allow += \$requiredMethods;
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!\$hasRequiredScheme) {
\$allowSchemes += \$requiredSchemes;
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return \$ret;
return $ret;
EOF;
@ -616,7 +636,7 @@ EOF;
*
* @throws \LogicException
*/
private function compileRoute(Route $route, string $name, bool $checkHost, bool $hasTrailingSlash, array $vars = null): string
private function compileRoute(Route $route, string $name, bool $checkHost, bool $hasTrailingSlash, bool $hasTrailingVar = false, array $vars = null): string
{
$compiledRoute = $route->compile();
$conditions = array();
@ -624,44 +644,69 @@ EOF;
$hostMatches = (bool) $compiledRoute->getHostVariables();
$methods = array_flip($route->getMethods());
$gotoname = 'not_'.preg_replace('/[^A-Za-z0-9_]/', '', $name);
$code = " // $name";
$code = " // $name\n";
if ('/' === $route->getPath()) {
$code .= "\n";
} elseif (!$matches) {
$code .= sprintf("
if ('/' !== \$pathinfo && '/' %s \$pathinfo[-1]) {%s
goto $gotoname;
}\n\n",
$hasTrailingSlash ? '!==' : '===',
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? "
if ('GET' === \$canonicalMethod) {
return \$allow = \$allowSchemes = array();
}" : ''
// no-op
} elseif (!$hasTrailingVar) {
$code .= sprintf(<<<'EOF'
if ('/' !== $pathinfo && $trimmedPathinfo %s $pathinfo) {%%s
goto %%s;
}
EOF
,
$hasTrailingSlash ? '===' : '!=='
);
} elseif ($hasTrailingSlash) {
$code .= sprintf("
if ('/' !== \$pathinfo[-1]) {%s
goto $gotoname;
$code .= <<<'EOF'
if ('/' !== $pathinfo && $trimmedPathinfo === $pathinfo) {%s
goto %s;
}
if ('/' !== \$pathinfo && preg_match(\$regex, substr(\$pathinfo, 0, -1), \$n) && \$m === (int) \$n['MARK']) {
\$matches = \$n;
}\n\n",
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? "
if ('GET' === \$canonicalMethod) {
return \$allow = \$allowSchemes = array();
}" : ''
);
if ('/' !== $pathinfo && preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
}
EOF;
} elseif ($this->supportsRedirections && (!$methods || isset($methods['GET']))) {
$code .= <<<'EOF'
$hasTrailingSlash = false;
if ($trimmedPathinfo === $pathinfo) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$code .= sprintf("
if ('/' !== \$pathinfo && '/' === \$pathinfo[-1] && preg_match(\$regex, substr(\$pathinfo, 0, -1), \$n) && \$m === (int) \$n['MARK']) {%s
goto $gotoname;
}\n\n",
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? "
if ('GET' === \$canonicalMethod) {
return \$allow = \$allowSchemes = array();
}" : ''
);
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {%s
if ($trimmedPathinfo === $pathinfo) {
goto %s;
}
}
EOF;
} else {
$code .= <<<'EOF'
if ($trimmedPathinfo === $pathinfo) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} elseif ('/' !== $pathinfo) {
goto %2$s;
}
EOF;
}
if ($this->supportsRedirections && (!$methods || isset($methods['GET']))) {
$code = sprintf($code, <<<'EOF'
if ('GET' === $canonicalMethod) {
return $allow = $allowSchemes = array();
}
EOF
,
$gotoname
)."\n\n";
} elseif ('/' !== $route->getPath()) {
$code = sprintf($code, '', $gotoname)."\n\n";
}
if ($vars) {

View File

@ -44,11 +44,11 @@ abstract class RedirectableUrlMatcher extends UrlMatcher implements Redirectable
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' === $pathinfo) {
} elseif ('/' === $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/') {
throw $e;
} else {
try {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
$pathinfo = $trimmedPathinfo === $pathinfo ? $pathinfo.'/' : $trimmedPathinfo;
$ret = parent::match($pathinfo);
return $this->redirect($pathinfo, $ret['_route'] ?? null) + $ret;

View File

@ -84,7 +84,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
{
$this->allow = $this->allowSchemes = array();
if ($ret = $this->matchCollection(rawurldecode($pathinfo), $this->routes)) {
if ($ret = $this->matchCollection(rawurldecode($pathinfo) ?: '/', $this->routes)) {
return $ret;
}
@ -134,49 +134,41 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
if ('HEAD' === $method = $this->context->getMethod()) {
$method = 'GET';
}
$supportsTrailingSlash = '/' !== $pathinfo && '' !== $pathinfo && $this instanceof RedirectableUrlMatcherInterface;
$supportsTrailingSlash = 'GET' === $method && $this instanceof RedirectableUrlMatcherInterface;
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
foreach ($routes as $name => $route) {
$compiledRoute = $route->compile();
$staticPrefix = $compiledRoute->getStaticPrefix();
$staticPrefix = rtrim($compiledRoute->getStaticPrefix(), '/');
$requiredMethods = $route->getMethods();
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
if ('' === $staticPrefix || 0 === strpos($pathinfo, $staticPrefix)) {
// no-op
} elseif (!$supportsTrailingSlash || ($requiredMethods && !\in_array('GET', $requiredMethods)) || 'GET' !== $method) {
continue;
} elseif ('/' === $staticPrefix[-1] && substr($staticPrefix, 0, -1) === $pathinfo) {
return $this->allow = $this->allowSchemes = array();
} elseif ('/' === $pathinfo[-1] && substr($pathinfo, 0, -1) === $staticPrefix) {
return $this->allow = $this->allowSchemes = array();
} else {
if ('' !== $staticPrefix && 0 !== strpos($trimmedPathinfo, $staticPrefix)) {
continue;
}
$regex = $compiledRoute->getRegex();
if ($supportsTrailingSlash) {
$pos = strrpos($regex, '$');
$hasTrailingSlash = '/' === $regex[$pos - 1];
$regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);
}
$pos = strrpos($regex, '$');
$hasTrailingSlash = '/' === $regex[$pos - 1];
$regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);
if (!preg_match($regex, $pathinfo, $matches)) {
continue;
}
if ($supportsTrailingSlash) {
if ('/' === $pathinfo[-1]) {
if (preg_match($regex, substr($pathinfo, 0, -1), $m)) {
$matches = $m;
} else {
$hasTrailingSlash = true;
}
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar = preg_match('#\{\w+\}/?$#', $route->getPath())) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $m)) {
$matches = $m;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ($supportsTrailingSlash && (!$requiredMethods || \in_array('GET', $requiredMethods))) {
return $this->allow = $this->allowSchemes = array();
}
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ((!$requiredMethods || \in_array('GET', $requiredMethods)) && 'GET' === $method) {
return $this->allow = $this->allowSchemes = array();
}
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
continue;
}
}

View File

@ -15,10 +15,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$this->context = $context;
}
public function match($rawPathinfo)
public function match($pathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();

View File

@ -15,10 +15,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$this->context = $context;
}
public function match($rawPathinfo)
public function match($pathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
@ -27,7 +28,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$canonicalMethod = 'GET';
}
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
switch ($trimmedPathinfo) {
default:
$routes = array(
'/test/baz' => array(array('_route' => 'baz'), null, null, null, false),
@ -53,11 +54,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo) {
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
break;
}
if ($requiredHost) {
@ -132,7 +130,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.')'
.')'
.')'
.')(?:/?)$}sD',
.')/?$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -140,10 +138,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
switch ($m = (int) $matches['MARK']) {
case 115:
// baz4
if ('/' !== $pathinfo[-1]) {
if ('/' !== $pathinfo && $trimmedPathinfo === $pathinfo) {
goto not_baz4;
}
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ('/' !== $pathinfo && preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
}
@ -153,10 +151,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
not_baz4:
// baz5
if ('/' !== $pathinfo[-1]) {
if ('/' !== $pathinfo && $trimmedPathinfo === $pathinfo) {
goto not_baz5;
}
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ('/' !== $pathinfo && preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
}
@ -170,10 +168,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
not_baz5:
// baz.baz6
if ('/' !== $pathinfo[-1]) {
if ('/' !== $pathinfo && $trimmedPathinfo === $pathinfo) {
goto not_bazbaz6;
}
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ('/' !== $pathinfo && preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
}
@ -189,7 +187,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
break;
case 160:
// foo1
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ($trimmedPathinfo === $pathinfo) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} elseif ('/' !== $pathinfo) {
goto not_foo1;
}
@ -207,7 +209,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
break;
case 204:
// foo2
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ($trimmedPathinfo === $pathinfo) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} elseif ('/' !== $pathinfo) {
goto not_foo2;
}
@ -219,7 +225,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
break;
case 279:
// foo3
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ($trimmedPathinfo === $pathinfo) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} elseif ('/' !== $pathinfo) {
goto not_foo3;
}
@ -231,37 +241,36 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
break;
default:
$routes = array(
47 => array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null, false),
70 => array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null, false),
90 => array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null, false),
131 => array(array('_route' => 'quoter'), array('quoter'), null, null, false),
168 => array(array('_route' => 'bar1'), array('bar'), null, null, false),
181 => array(array('_route' => 'overridden'), array('var'), null, null, false),
212 => array(array('_route' => 'bar2'), array('bar1'), null, null, false),
248 => array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null, false),
287 => array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null, false),
309 => array(array('_route' => 'foo4'), array('foo'), null, null, false),
371 => array(array('_route' => 'route13'), array('var1', 'name'), null, null, false),
389 => array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null, false),
441 => array(array('_route' => 'route15'), array('name'), null, null, false),
489 => array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null, false),
510 => array(array('_route' => 'a'), array(), null, null, false),
531 => array(array('_route' => 'b'), array('var'), null, null, false),
549 => array(array('_route' => 'c'), array('var'), null, null, false),
47 => array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null, false, true),
70 => array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null, false, true),
90 => array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null, false, true),
131 => array(array('_route' => 'quoter'), array('quoter'), null, null, false, true),
168 => array(array('_route' => 'bar1'), array('bar'), null, null, false, true),
181 => array(array('_route' => 'overridden'), array('var'), null, null, false, true),
212 => array(array('_route' => 'bar2'), array('bar1'), null, null, false, true),
248 => array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null, false, true),
287 => array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null, false, true),
309 => array(array('_route' => 'foo4'), array('foo'), null, null, false, true),
371 => array(array('_route' => 'route13'), array('var1', 'name'), null, null, false, true),
389 => array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null, false, true),
441 => array(array('_route' => 'route15'), array('name'), null, null, false, true),
489 => array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null, false, true),
510 => array(array('_route' => 'a'), array(), null, null, false, false),
531 => array(array('_route' => 'b'), array('var'), null, null, false, true),
549 => array(array('_route' => 'c'), array('var'), null, null, false, true),
);
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $hasTrailingVar) = $routes[$m];
if ('/' !== $pathinfo) {
if ('/' === $pathinfo[-1]) {
if (preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
}
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
break;
}
}

View File

@ -37,8 +37,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $pathinfo) {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
} elseif ('/' !== $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/') {
$pathinfo = $trimmedPathinfo === $pathinfo ? $pathinfo.'/' : $trimmedPathinfo;
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
@ -50,10 +50,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
private function doMatch(string $pathinfo, array &$allow = array(), array &$allowSchemes = array()): array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -92,7 +93,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
.')'
.')'
.'|/(en|fr)?(*:264)'
.')(?:/?)$}sD',
.')/?$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -100,37 +101,36 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
32 => array(array('_route' => 'a', '_locale' => 'en'), array('_locale'), null, null, true),
46 => array(array('_route' => 'b', '_locale' => 'en'), array('_locale'), null, null, false),
58 => array(array('_route' => 'c', '_locale' => 'en'), array('_locale', 'id'), null, null, false),
75 => array(array('_route' => 'd', '_locale' => 'en'), array('_locale', 'id'), null, null, false),
94 => array(array('_route' => 'e', '_locale' => 'en'), array('_locale', 'id'), null, null, false),
110 => array(array('_route' => 'f', '_locale' => 'en'), array('_locale'), null, null, true),
130 => array(array('_route' => 'g', '_locale' => 'en'), array('_locale'), null, null, false),
154 => array(array('_route' => 'h', '_locale' => 'en'), array('_locale', 'page'), null, null, false),
175 => array(array('_route' => 'i', '_locale' => 'en'), array('_locale', 'page'), null, null, false),
202 => array(array('_route' => 'j', '_locale' => 'en'), array('_locale', 'id'), null, null, false),
216 => array(array('_route' => 'k', '_locale' => 'en'), array('_locale'), null, null, false),
234 => array(array('_route' => 'l', '_locale' => 'en'), array('_locale'), null, null, false),
245 => array(array('_route' => 'm', '_locale' => 'en'), array('_locale'), null, null, false),
264 => array(array('_route' => 'n', '_locale' => 'en'), array('_locale'), null, null, false),
32 => array(array('_route' => 'a', '_locale' => 'en'), array('_locale'), null, null, true, false),
46 => array(array('_route' => 'b', '_locale' => 'en'), array('_locale'), null, null, false, false),
58 => array(array('_route' => 'c', '_locale' => 'en'), array('_locale', 'id'), null, null, false, true),
75 => array(array('_route' => 'd', '_locale' => 'en'), array('_locale', 'id'), null, null, false, false),
94 => array(array('_route' => 'e', '_locale' => 'en'), array('_locale', 'id'), null, null, false, false),
110 => array(array('_route' => 'f', '_locale' => 'en'), array('_locale'), null, null, true, false),
130 => array(array('_route' => 'g', '_locale' => 'en'), array('_locale'), null, null, false, false),
154 => array(array('_route' => 'h', '_locale' => 'en'), array('_locale', 'page'), null, null, false, true),
175 => array(array('_route' => 'i', '_locale' => 'en'), array('_locale', 'page'), null, null, false, true),
202 => array(array('_route' => 'j', '_locale' => 'en'), array('_locale', 'id'), null, null, false, false),
216 => array(array('_route' => 'k', '_locale' => 'en'), array('_locale'), null, null, false, false),
234 => array(array('_route' => 'l', '_locale' => 'en'), array('_locale'), null, null, false, false),
245 => array(array('_route' => 'm', '_locale' => 'en'), array('_locale'), null, null, false, false),
264 => array(array('_route' => 'n', '_locale' => 'en'), array('_locale'), null, null, false, true),
);
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $hasTrailingVar) = $routes[$m];
if ('/' !== $pathinfo) {
if ('/' === $pathinfo[-1]) {
if (preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ('GET' === $canonicalMethod && (!$requiredMethods || isset($requiredMethods['GET']))) {
return $allow = $allowSchemes = array();
}
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
return $allow = $allowSchemes = array();
}
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
break;
}
}

View File

@ -15,10 +15,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$this->context = $context;
}
public function match($rawPathinfo)
public function match($pathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -45,7 +46,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.')'
.')'
.')'
.')(?:/?)$}sD',
.')/?$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -53,26 +54,25 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
27 => array(array('_route' => 'r1'), array('foo'), null, null, false),
38 => array(array('_route' => 'r10'), array('foo'), null, null, false),
46 => array(array('_route' => 'r100'), array('foo'), null, null, false),
59 => array(array('_route' => 'r2'), array('foo'), null, null, false),
70 => array(array('_route' => 'r20'), array('foo'), null, null, false),
78 => array(array('_route' => 'r200'), array('foo'), null, null, false),
27 => array(array('_route' => 'r1'), array('foo'), null, null, false, false),
38 => array(array('_route' => 'r10'), array('foo'), null, null, false, false),
46 => array(array('_route' => 'r100'), array('foo'), null, null, false, false),
59 => array(array('_route' => 'r2'), array('foo'), null, null, false, false),
70 => array(array('_route' => 'r20'), array('foo'), null, null, false, false),
78 => array(array('_route' => 'r200'), array('foo'), null, null, false, false),
);
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $hasTrailingVar) = $routes[$m];
if ('/' !== $pathinfo) {
if ('/' === $pathinfo[-1]) {
if (preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
}
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
break;
}
}

View File

@ -15,10 +15,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$this->context = $context;
}
public function match($rawPathinfo)
public function match($pathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
@ -35,7 +36,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.'|(*:56)'
.')'
.')'
.')(?:/?)$}sD',
.')/?$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -43,7 +44,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
switch ($m = (int) $matches['MARK']) {
case 56:
// r1
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ($trimmedPathinfo === $pathinfo) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} elseif ('/' !== $pathinfo) {
goto not_r1;
}
@ -53,7 +58,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
not_r1:
// r2
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ($trimmedPathinfo === $pathinfo) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} elseif ('/' !== $pathinfo) {
goto not_r2;
}

View File

@ -37,8 +37,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $pathinfo) {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
} elseif ('/' !== $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/') {
$pathinfo = $trimmedPathinfo === $pathinfo ? $pathinfo.'/' : $trimmedPathinfo;
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
@ -50,10 +50,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
private function doMatch(string $pathinfo, array &$allow = array(), array &$allowSchemes = array()): array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
@ -62,7 +63,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
$canonicalMethod = 'GET';
}
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
switch ($trimmedPathinfo) {
default:
$routes = array(
'/test/baz' => array(array('_route' => 'baz'), null, null, null, false),
@ -90,14 +91,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo) {
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
return $allow = $allowSchemes = array();
}
break;
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ('GET' === $canonicalMethod && (!$requiredMethods || isset($requiredMethods['GET']))) {
return $allow = $allowSchemes = array();
}
break;
}
if ($requiredHost) {
@ -172,7 +170,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
.')'
.')'
.')'
.')(?:/?)$}sD',
.')/?$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -180,13 +178,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
switch ($m = (int) $matches['MARK']) {
case 115:
// baz4
if ('/' !== $pathinfo[-1]) {
if ('/' !== $pathinfo && $trimmedPathinfo === $pathinfo) {
if ('GET' === $canonicalMethod) {
return $allow = $allowSchemes = array();
}
goto not_baz4;
}
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ('/' !== $pathinfo && preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
}
@ -196,10 +194,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
not_baz4:
// baz5
if ('/' !== $pathinfo[-1]) {
if ('/' !== $pathinfo && $trimmedPathinfo === $pathinfo) {
goto not_baz5;
}
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ('/' !== $pathinfo && preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
}
@ -213,10 +211,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
not_baz5:
// baz.baz6
if ('/' !== $pathinfo[-1]) {
if ('/' !== $pathinfo && $trimmedPathinfo === $pathinfo) {
goto not_bazbaz6;
}
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ('/' !== $pathinfo && preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
}
@ -232,7 +230,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
break;
case 160:
// foo1
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
if ($trimmedPathinfo === $pathinfo) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} elseif ('/' !== $pathinfo) {
goto not_foo1;
}
@ -250,11 +252,22 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
break;
case 204:
// foo2
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$hasTrailingSlash = false;
if ($trimmedPathinfo === $pathinfo) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ('GET' === $canonicalMethod) {
return $allow = $allowSchemes = array();
}
goto not_foo2;
if ($trimmedPathinfo === $pathinfo) {
goto not_foo2;
}
}
$matches = array('foo1' => $matches[1] ?? null);
@ -265,11 +278,22 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
break;
case 279:
// foo3
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$hasTrailingSlash = false;
if ($trimmedPathinfo === $pathinfo) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ('GET' === $canonicalMethod) {
return $allow = $allowSchemes = array();
}
goto not_foo3;
if ($trimmedPathinfo === $pathinfo) {
goto not_foo3;
}
}
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
@ -280,40 +304,39 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
break;
default:
$routes = array(
47 => array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null, false),
70 => array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null, false),
90 => array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null, false),
131 => array(array('_route' => 'quoter'), array('quoter'), null, null, false),
168 => array(array('_route' => 'bar1'), array('bar'), null, null, false),
181 => array(array('_route' => 'overridden'), array('var'), null, null, false),
212 => array(array('_route' => 'bar2'), array('bar1'), null, null, false),
248 => array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null, false),
287 => array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null, false),
309 => array(array('_route' => 'foo4'), array('foo'), null, null, false),
371 => array(array('_route' => 'route13'), array('var1', 'name'), null, null, false),
389 => array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null, false),
441 => array(array('_route' => 'route15'), array('name'), null, null, false),
489 => array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null, false),
510 => array(array('_route' => 'a'), array(), null, null, false),
531 => array(array('_route' => 'b'), array('var'), null, null, false),
549 => array(array('_route' => 'c'), array('var'), null, null, false),
47 => array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null, false, true),
70 => array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null, false, true),
90 => array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null, false, true),
131 => array(array('_route' => 'quoter'), array('quoter'), null, null, false, true),
168 => array(array('_route' => 'bar1'), array('bar'), null, null, false, true),
181 => array(array('_route' => 'overridden'), array('var'), null, null, false, true),
212 => array(array('_route' => 'bar2'), array('bar1'), null, null, false, true),
248 => array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null, false, true),
287 => array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null, false, true),
309 => array(array('_route' => 'foo4'), array('foo'), null, null, false, true),
371 => array(array('_route' => 'route13'), array('var1', 'name'), null, null, false, true),
389 => array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null, false, true),
441 => array(array('_route' => 'route15'), array('name'), null, null, false, true),
489 => array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null, false, true),
510 => array(array('_route' => 'a'), array(), null, null, false, false),
531 => array(array('_route' => 'b'), array('var'), null, null, false, true),
549 => array(array('_route' => 'c'), array('var'), null, null, false, true),
);
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $hasTrailingVar) = $routes[$m];
if ('/' !== $pathinfo) {
if ('/' === $pathinfo[-1]) {
if (preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ('GET' === $canonicalMethod && (!$requiredMethods || isset($requiredMethods['GET']))) {
return $allow = $allowSchemes = array();
}
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
return $allow = $allowSchemes = array();
}
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
break;
}
}

View File

@ -15,10 +15,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$this->context = $context;
}
public function match($rawPathinfo)
public function match($pathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -26,10 +27,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$canonicalMethod = 'GET';
}
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
switch ($trimmedPathinfo) {
case '/with-condition':
// with-condition
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
if ('/' !== $pathinfo && $trimmedPathinfo !== $pathinfo) {
goto not_withcondition;
}
@ -47,11 +48,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo) {
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
break;
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
@ -73,7 +71,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$regexList = array(
0 => '{^(?'
.'|/rootprefix/([^/]++)(*:27)'
.')(?:/?)$}sD',
.')/?$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -81,21 +79,20 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
27 => array(array('_route' => 'dynamic'), array('var'), null, null, false),
27 => array(array('_route' => 'dynamic'), array('var'), null, null, false, true),
);
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $hasTrailingVar) = $routes[$m];
if ('/' !== $pathinfo) {
if ('/' === $pathinfo[-1]) {
if (preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
}
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
break;
}
}

View File

@ -15,10 +15,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$this->context = $context;
}
public function match($rawPathinfo)
public function match($pathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -26,10 +27,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$canonicalMethod = 'GET';
}
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
switch ($trimmedPathinfo) {
case '/put_and_post':
// put_and_post
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
if ('/' !== $pathinfo && $trimmedPathinfo !== $pathinfo) {
goto not_put_and_post;
}
@ -42,7 +43,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
return $ret;
not_put_and_post:
// put_and_get_and_head
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
if ('/' !== $pathinfo && $trimmedPathinfo !== $pathinfo) {
goto not_put_and_get_and_head;
}
@ -67,11 +68,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo) {
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
break;
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);

View File

@ -37,8 +37,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $pathinfo) {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
} elseif ('/' !== $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/') {
$pathinfo = $trimmedPathinfo === $pathinfo ? $pathinfo.'/' : $trimmedPathinfo;
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
@ -50,10 +50,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
private function doMatch(string $pathinfo, array &$allow = array(), array &$allowSchemes = array()): array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -61,7 +62,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
$canonicalMethod = 'GET';
}
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
switch ($trimmedPathinfo) {
default:
$routes = array(
'/a/11' => array(array('_route' => 'a_first'), null, null, null, false),
@ -82,14 +83,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo) {
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
return $allow = $allowSchemes = array();
}
break;
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ('GET' === $canonicalMethod && (!$requiredMethods || isset($requiredMethods['GET']))) {
return $allow = $allowSchemes = array();
}
break;
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
@ -112,7 +110,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
0 => '{^(?'
.'|/([^/]++)(*:16)'
.'|/nested/([^/]++)(*:39)'
.')(?:/?)$}sD',
.')/?$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -120,25 +118,24 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
16 => array(array('_route' => 'a_wildcard'), array('param'), null, null, false),
39 => array(array('_route' => 'nested_wildcard'), array('param'), null, null, false),
16 => array(array('_route' => 'a_wildcard'), array('param'), null, null, false, true),
39 => array(array('_route' => 'nested_wildcard'), array('param'), null, null, false, true),
);
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $hasTrailingVar) = $routes[$m];
if ('/' !== $pathinfo) {
if ('/' === $pathinfo[-1]) {
if (preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ('GET' === $canonicalMethod && (!$requiredMethods || isset($requiredMethods['GET']))) {
return $allow = $allowSchemes = array();
}
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
return $allow = $allowSchemes = array();
}
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
break;
}
}

View File

@ -15,10 +15,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$this->context = $context;
}
public function match($rawPathinfo)
public function match($pathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -26,7 +27,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$canonicalMethod = 'GET';
}
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
switch ($trimmedPathinfo) {
default:
$routes = array(
'/trailing/simple/no-methods' => array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null, true),
@ -43,11 +44,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo) {
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
break;
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
@ -80,7 +78,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.'|head\\-method/([^/]++)(*:240)'
.'|post\\-method/([^/]++)(*:269)'
.')'
.')(?:/?)$}sD',
.')/?$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -88,28 +86,27 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
46 => array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null, true),
73 => array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, true),
101 => array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, true),
130 => array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, true),
183 => array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null, false),
211 => array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, false),
240 => array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, false),
269 => array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, false),
46 => array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null, true, true),
73 => array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, true, true),
101 => array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, true, true),
130 => array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, true, true),
183 => array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null, false, true),
211 => array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, false, true),
240 => array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, false, true),
269 => array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, false, true),
);
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $hasTrailingVar) = $routes[$m];
if ('/' !== $pathinfo) {
if ('/' === $pathinfo[-1]) {
if (preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
}
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
break;
}
}

View File

@ -37,8 +37,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $pathinfo) {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
} elseif ('/' !== $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/') {
$pathinfo = $trimmedPathinfo === $pathinfo ? $pathinfo.'/' : $trimmedPathinfo;
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
@ -50,10 +50,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
private function doMatch(string $pathinfo, array &$allow = array(), array &$allowSchemes = array()): array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -61,7 +62,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
$canonicalMethod = 'GET';
}
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
switch ($trimmedPathinfo) {
default:
$routes = array(
'/trailing/simple/no-methods' => array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null, true),
@ -78,14 +79,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo) {
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
return $allow = $allowSchemes = array();
}
break;
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ('GET' === $canonicalMethod && (!$requiredMethods || isset($requiredMethods['GET']))) {
return $allow = $allowSchemes = array();
}
break;
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
@ -118,7 +116,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
.'|head\\-method/([^/]++)(*:240)'
.'|post\\-method/([^/]++)(*:269)'
.')'
.')(?:/?)$}sD',
.')/?$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -126,31 +124,30 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
46 => array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null, true),
73 => array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, true),
101 => array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, true),
130 => array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, true),
183 => array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null, false),
211 => array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, false),
240 => array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, false),
269 => array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, false),
46 => array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null, true, true),
73 => array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, true, true),
101 => array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, true, true),
130 => array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, true, true),
183 => array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null, false, true),
211 => array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, false, true),
240 => array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, false, true),
269 => array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, false, true),
);
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $hasTrailingVar) = $routes[$m];
if ('/' !== $pathinfo) {
if ('/' === $pathinfo[-1]) {
if (preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ('GET' === $canonicalMethod && (!$requiredMethods || isset($requiredMethods['GET']))) {
return $allow = $allowSchemes = array();
}
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
return $allow = $allowSchemes = array();
}
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
break;
}
}

View File

@ -15,10 +15,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$this->context = $context;
}
public function match($rawPathinfo)
public function match($pathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -30,13 +31,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$regexList = array(
0 => '{^(?'
.'|/(a)(*:11)'
.')(?:/?)$}sD',
.')/?$}sD',
11 => '{^(?'
.'|/(.)(*:22)'
.')(?:/?)$}sDu',
.')/?$}sDu',
22 => '{^(?'
.'|/(.)(*:33)'
.')(?:/?)$}sD',
.')/?$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -44,23 +45,22 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
11 => array(array('_route' => 'a'), array('a'), null, null, false),
22 => array(array('_route' => 'b'), array('a'), null, null, false),
33 => array(array('_route' => 'c'), array('a'), null, null, false),
11 => array(array('_route' => 'a'), array('a'), null, null, false, true),
22 => array(array('_route' => 'b'), array('a'), null, null, false, true),
33 => array(array('_route' => 'c'), array('a'), null, null, false, true),
);
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $hasTrailingVar) = $routes[$m];
if ('/' !== $pathinfo) {
if ('/' === $pathinfo[-1]) {
if (preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
}
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
// no-op
} elseif (preg_match($regex, $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
$matches = $n;
} else {
$hasTrailingSlash = true;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
break;
}
}

View File

@ -15,10 +15,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$this->context = $context;
}
public function match($rawPathinfo)
public function match($pathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
@ -27,7 +28,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$canonicalMethod = 'GET';
}
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
switch ($trimmedPathinfo) {
case '/':
// a
if (preg_match('#^(?P<d>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', $host, $hostMatches)) {

View File

@ -706,6 +706,16 @@ class UrlMatcherTest extends TestCase
$matcher = $this->getUrlMatcher($coll);
$this->assertSame(array('_route' => 'b'), $matcher->match('/bar/'));
$coll = new RouteCollection();
$coll->add('a', new Route('/dav/{foo<.*>?}', array(), array(), array(), '', array(), array('GET', 'OPTIONS')));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'OPTIONS'));
$expected = array(
'_route' => 'a',
'foo' => 'files/bar',
);
$this->assertEquals($expected, $matcher->match('/dav/files/bar/'));
}
public function testSlashAndVerbPrecedence()