bug #29298 [Routing] fix trailing slash redirection when using RedirectableUrlMatcher (nicolas-grekas)

This PR was merged into the 4.1 branch.

Discussion
----------

[Routing] fix trailing slash redirection when using RedirectableUrlMatcher

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

This is #29297 for 4.1

Commits
-------

6968000a3c [Routing] fix trailing slash redirection when using RedirectableUrlMatcher
This commit is contained in:
Nicolas Grekas 2018-11-26 11:24:14 +01:00
commit 95ebc9f38f
17 changed files with 1520 additions and 1323 deletions

View File

@ -29,6 +29,7 @@ class PhpMatcherDumper extends MatcherDumper
{
private $expressionLanguage;
private $signalingException;
private $supportsRedirections;
/**
* @var ExpressionFunctionProviderInterface[]
@ -56,7 +57,7 @@ class PhpMatcherDumper extends MatcherDumper
// trailing slash support is only enabled if we know how to redirect the user
$interfaces = class_implements($options['base_class']);
$supportsRedirections = isset($interfaces[RedirectableUrlMatcherInterface::class]);
$this->supportsRedirections = isset($interfaces[RedirectableUrlMatcherInterface::class]);
return <<<EOF
<?php
@ -76,7 +77,7 @@ class {$options['class']} extends {$options['base_class']}
\$this->context = \$context;
}
{$this->generateMatchMethod($supportsRedirections)}
{$this->generateMatchMethod()}
}
EOF;
@ -90,7 +91,7 @@ EOF;
/**
* Generates the code for the match method implementing UrlMatcherInterface.
*/
private function generateMatchMethod(bool $supportsRedirections): string
private function generateMatchMethod(): string
{
// Group hosts by same-suffix, re-order when possible
$matchHost = false;
@ -111,7 +112,7 @@ EOF;
$code = <<<EOF
{
\$allow = \$allowSchemes = array();
\$pathinfo = rawurldecode(\$rawPathinfo);
\$pathinfo = rawurldecode(\$rawPathinfo) ?: '/';
\$context = \$this->context;
\$requestMethod = \$canonicalMethod = \$context->getMethod();
{$fetchHost}
@ -123,7 +124,7 @@ $code
EOF;
if ($supportsRedirections) {
if ($this->supportsRedirections) {
return <<<'EOF'
public function match($pathinfo)
{
@ -213,9 +214,18 @@ EOF
$compiledRoute = $route->compile();
$hostRegex = $compiledRoute->getHostRegex();
$regex = $compiledRoute->getRegex();
if ($hasTrailingSlash = '/' !== $route->getPath()) {
$pos = strrpos($regex, '$');
$hasTrailingSlash = '/' === $regex[$pos - 1];
$regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);
}
if (!$compiledRoute->getPathVariables()) {
$host = !$compiledRoute->getHostVariables() ? $route->getHost() : '';
$url = $route->getPath();
if ($hasTrailingSlash) {
$url = substr($url, 0, -1);
}
foreach ($dynamicRegex as list($hostRx, $rx)) {
if (preg_match($rx, $url) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
$dynamicRegex[] = array($hostRegex, $regex);
@ -224,7 +234,7 @@ EOF
}
}
$staticRoutes[$url][$name] = $route;
$staticRoutes[$url][$name] = array($route, $hasTrailingSlash);
} else {
$dynamicRegex[] = array($hostRegex, $regex);
$dynamicRoutes->add($name, $route);
@ -251,7 +261,7 @@ EOF
foreach ($staticRoutes as $url => $routes) {
if (1 === \count($routes)) {
foreach ($routes as $name => $route) {
foreach ($routes as $name => list($route, $hasTrailingSlash)) {
}
if (!$route->getCondition()) {
@ -261,20 +271,21 @@ EOF
unset($defaults['_canonical_route']);
}
$default .= sprintf(
"%s => array(%s, %s, %s, %s),\n",
"%s => array(%s, %s, %s, %s, %s),\n",
self::export($url),
self::export(array('_route' => $name) + $defaults),
self::export(!$route->compile()->getHostVariables() ? $route->getHost() : $route->compile()->getHostRegex() ?: null),
self::export(array_flip($route->getMethods()) ?: null),
self::export(array_flip($route->getSchemes()) ?: null)
self::export(array_flip($route->getSchemes()) ?: null),
self::export($hasTrailingSlash)
);
continue;
}
}
$code .= sprintf(" case %s:\n", self::export($url));
foreach ($routes as $name => $route) {
$code .= $this->compileRoute($route, $name, true);
foreach ($routes as $name => list($route, $hasTrailingSlash)) {
$code .= $this->compileRoute($route, $name, true, $hasTrailingSlash);
}
$code .= " break;\n";
}
@ -285,15 +296,15 @@ EOF
\$routes = array(
{$this->indent($default, 4)} );
if (!isset(\$routes[\$pathinfo])) {
if (!isset(\$routes[\$trimmedPathinfo])) {
break;
}
list(\$ret, \$requiredHost, \$requiredMethods, \$requiredSchemes) = \$routes[\$pathinfo];
list(\$ret, \$requiredHost, \$requiredMethods, \$requiredSchemes, \$hasTrailingSlash) = \$routes[\$trimmedPathinfo];
{$this->compileSwitchDefault(false, $matchHost)}
EOF;
}
return sprintf(" switch (\$pathinfo) {\n%s }\n\n", $this->indent($code));
return sprintf(" switch (\$trimmedPathinfo = '/' !== \$pathinfo && '/' === \$pathinfo[-1] ? substr(\$pathinfo, 0, -1) : \$pathinfo) {\n%s }\n\n", $this->indent($code));
}
/**
@ -394,7 +405,11 @@ EOF;
$state->vars = array();
$regex = preg_replace_callback('#\?P<([^>]++)>#', $state->getVars, $rx[1]);
$tree->addRoute($regex, array($name, $regex, $state->vars, $route));
if ($hasTrailingSlash = '/' !== $regex && '/' === $regex[-1]) {
$regex = substr($regex, 0, -1);
}
$tree->addRoute($regex, array($name, $regex, $state->vars, $route, $hasTrailingSlash));
}
$code .= $this->compileStaticPrefixCollection($tree, $state);
@ -403,7 +418,7 @@ EOF;
$code .= "\n .')'";
$state->regex .= ')';
}
$rx = ")$}{$modifiers}";
$rx = ")(?:/?)$}{$modifiers}";
$code .= "\n .'{$rx}',";
$state->regex .= $rx;
$state->markTail = 0;
@ -423,7 +438,7 @@ EOF;
\$routes = array(
{$this->indent($state->default, 4)} );
list(\$ret, \$vars, \$requiredMethods, \$requiredSchemes) = \$routes[\$m];
list(\$ret, \$vars, \$requiredMethods, \$requiredSchemes, \$hasTrailingSlash) = \$routes[\$m];
{$this->compileSwitchDefault(true, $matchHost)}
EOF;
}
@ -478,11 +493,11 @@ EOF;
continue;
}
list($name, $regex, $vars, $route) = $route;
list($name, $regex, $vars, $route, $hasTrailingSlash) = $route;
$compiledRoute = $route->compile();
if ($compiledRoute->getRegex() === $prevRegex) {
$state->switch = substr_replace($state->switch, $this->compileRoute($route, $name, false)."\n", -19, 0);
$state->switch = substr_replace($state->switch, $this->compileRoute($route, $name, false, $hasTrailingSlash)."\n", -19, 0);
continue;
}
@ -501,12 +516,13 @@ EOF;
unset($defaults['_canonical_route']);
}
$state->default .= sprintf(
"%s => array(%s, %s, %s, %s),\n",
"%s => array(%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(array_flip($route->getSchemes()) ?: null),
self::export($hasTrailingSlash)
);
} else {
$prevRegex = $compiledRoute->getRegex();
@ -518,7 +534,7 @@ EOF;
$state->switch .= <<<EOF
case {$state->mark}:
{$combine}{$this->compileRoute($route, $name, false)}
{$combine}{$this->compileRoute($route, $name, false, $hasTrailingSlash)}
break;
EOF;
@ -533,8 +549,15 @@ EOF;
*/
private function compileSwitchDefault(bool $hasVars, bool $matchHost): string
{
$code = sprintf("
if ('/' !== \$pathinfo && \$hasTrailingSlash !== ('/' === \$pathinfo[-1])) {
%s;
}\n",
$this->supportsRedirections ? 'return null' : 'break'
);
if ($hasVars) {
$code = <<<EOF
$code .= <<<EOF
foreach (\$vars as \$i => \$v) {
if (isset(\$matches[1 + \$i])) {
@ -544,7 +567,7 @@ EOF;
EOF;
} elseif ($matchHost) {
$code = <<<EOF
$code .= <<<EOF
if (\$requiredHost) {
if ('#' !== \$requiredHost[0] ? \$requiredHost !== \$host : !preg_match(\$requiredHost, \$host, \$hostMatches)) {
@ -557,8 +580,6 @@ EOF;
}
EOF;
} else {
$code = '';
}
$code .= <<<EOF
@ -587,9 +608,22 @@ EOF;
*
* @throws \LogicException
*/
private function compileRoute(Route $route, string $name, bool $checkHost): string
private function compileRoute(Route $route, string $name, bool $checkHost, bool $hasTrailingSlash): string
{
$code = '';
$code = " // $name";
if ('/' !== $route->getPath()) {
$code .= sprintf("
if ('/' !== \$pathinfo && '/' %s \$pathinfo[-1]) {
%s;
}\n",
$hasTrailingSlash ? '!==' : '===',
$this->supportsRedirections ? 'return null' : 'break'
);
} else {
$code .= "\n";
}
$compiledRoute = $route->compile();
$conditions = array();
$matches = (bool) $compiledRoute->getPathVariables();
@ -617,12 +651,11 @@ EOF;
if ($conditions) {
$code .= <<<EOF
// $name
if ($conditions) {
EOF;
} else {
$code .= " // {$name}\n";
$code = $this->indent($code);
}
$gotoname = 'not_'.preg_replace('/[^A-Za-z0-9_]/', '', $name);

View File

@ -130,16 +130,38 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
*/
protected function matchCollection($pathinfo, RouteCollection $routes)
{
$supportsTrailingSlash = '/' !== $pathinfo && '' !== $pathinfo && $this instanceof RedirectableUrlMatcherInterface;
foreach ($routes as $name => $route) {
$compiledRoute = $route->compile();
$staticPrefix = $compiledRoute->getStaticPrefix();
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
if ('' === $staticPrefix || 0 === strpos($pathinfo, $staticPrefix)) {
// no-op
} elseif (!$supportsTrailingSlash) {
continue;
} elseif ('/' === $staticPrefix[-1] && substr($staticPrefix, 0, -1) === $pathinfo) {
return;
} elseif ('/' === $pathinfo[-1] && substr($pathinfo, 0, -1) === $staticPrefix) {
return;
} else {
continue;
}
$regex = $compiledRoute->getRegex();
if ($supportsTrailingSlash) {
$pos = strrpos($regex, '$');
$hasTrailingSlash = '/' === $regex[$pos - 1];
$regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);
}
if (!preg_match($regex, $pathinfo, $matches)) {
continue;
}
if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
continue;
if ($supportsTrailingSlash && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
return;
}
$hostMatches = array();

View File

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

View File

@ -18,7 +18,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
@ -27,32 +27,36 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
default:
$routes = array(
'/test/baz' => array(array('_route' => 'baz'), null, null, null),
'/test/baz.html' => array(array('_route' => 'baz2'), null, null, null),
'/test/baz3/' => array(array('_route' => 'baz3'), null, null, null),
'/foofoo' => array(array('_route' => 'foofoo', 'def' => 'test'), null, null, null),
'/spa ce' => array(array('_route' => 'space'), null, null, null),
'/multi/new' => array(array('_route' => 'overridden2'), null, null, null),
'/multi/hey/' => array(array('_route' => 'hey'), null, null, null),
'/ababa' => array(array('_route' => 'ababa'), null, null, null),
'/route1' => array(array('_route' => 'route1'), 'a.example.com', null, null),
'/c2/route2' => array(array('_route' => 'route2'), 'a.example.com', null, null),
'/route4' => array(array('_route' => 'route4'), 'a.example.com', null, null),
'/c2/route3' => array(array('_route' => 'route3'), 'b.example.com', null, null),
'/route5' => array(array('_route' => 'route5'), 'c.example.com', null, null),
'/route6' => array(array('_route' => 'route6'), null, null, null),
'/route11' => array(array('_route' => 'route11'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null),
'/route12' => array(array('_route' => 'route12', 'var1' => 'val'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null),
'/route17' => array(array('_route' => 'route17'), null, null, null),
'/test/baz' => array(array('_route' => 'baz'), null, null, null, false),
'/test/baz.html' => array(array('_route' => 'baz2'), null, null, null, false),
'/test/baz3' => array(array('_route' => 'baz3'), null, null, null, true),
'/foofoo' => array(array('_route' => 'foofoo', 'def' => 'test'), null, null, null, false),
'/spa ce' => array(array('_route' => 'space'), null, null, null, false),
'/multi/new' => array(array('_route' => 'overridden2'), null, null, null, false),
'/multi/hey' => array(array('_route' => 'hey'), null, null, null, true),
'/ababa' => array(array('_route' => 'ababa'), null, null, null, false),
'/route1' => array(array('_route' => 'route1'), 'a.example.com', null, null, false),
'/c2/route2' => array(array('_route' => 'route2'), 'a.example.com', null, null, false),
'/route4' => array(array('_route' => 'route4'), 'a.example.com', null, null, false),
'/c2/route3' => array(array('_route' => 'route3'), 'b.example.com', null, null, false),
'/route5' => array(array('_route' => 'route5'), 'c.example.com', null, null, false),
'/route6' => array(array('_route' => 'route6'), null, null, null, false),
'/route11' => array(array('_route' => 'route11'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false),
'/route12' => array(array('_route' => 'route12', 'var1' => 'val'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false),
'/route17' => array(array('_route' => 'route17'), null, null, null, false),
);
if (!isset($routes[$pathinfo])) {
if (!isset($routes[$trimmedPathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
if ($requiredHost) {
if ('#' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) {
@ -88,57 +92,63 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.'|/([^/]++)(*:70)'
.'|head/([^/]++)(*:90)'
.')'
.'|/test/([^/]++)/(?'
.'|(*:116)'
.'|/test/([^/]++)(?'
.'|(*:115)'
.')'
.'|/([\']+)(*:132)'
.'|/([\']+)(*:131)'
.'|/a/(?'
.'|b\'b/([^/]++)(?'
.'|(*:161)'
.'|(*:169)'
.'|(*:160)'
.'|(*:168)'
.')'
.'|(.*)(*:182)'
.'|(.*)(*:181)'
.'|b\'b/([^/]++)(?'
.'|(*:205)'
.'|(*:213)'
.'|(*:204)'
.'|(*:212)'
.')'
.')'
.'|/multi/hello(?:/([^/]++))?(*:249)'
.'|/multi/hello(?:/([^/]++))?(*:248)'
.'|/([^/]++)/b/([^/]++)(?'
.'|(*:280)'
.'|(*:288)'
.'|(*:279)'
.'|(*:287)'
.')'
.'|/aba/([^/]++)(*:310)'
.'|/aba/([^/]++)(*:309)'
.')|(?i:([^\\.]++)\\.example\\.com)\\.(?'
.'|/route1(?'
.'|3/([^/]++)(*:372)'
.'|4/([^/]++)(*:390)'
.'|3/([^/]++)(*:371)'
.'|4/([^/]++)(*:389)'
.')'
.')|(?i:c\\.example\\.com)\\.(?'
.'|/route15/([^/]++)(*:442)'
.'|/route15/([^/]++)(*:441)'
.')|(?:(?:[^./]*+\\.)++)(?'
.'|/route16/([^/]++)(*:490)'
.'|/route16/([^/]++)(*:489)'
.'|/a/(?'
.'|a\\.\\.\\.(*:511)'
.'|a\\.\\.\\.(*:510)'
.'|b/(?'
.'|([^/]++)(*:532)'
.'|c/([^/]++)(*:550)'
.'|([^/]++)(*:531)'
.'|c/([^/]++)(*:549)'
.')'
.')'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
case 116:
case 115:
$matches = array('foo' => $matches[1] ?? null);
// baz4
if ('/' !== $pathinfo && '/' !== $pathinfo[-1]) {
break;
}
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
// baz5
if ('/' !== $pathinfo && '/' !== $pathinfo[-1]) {
break;
}
$ret = $this->mergeDefaults(array('_route' => 'baz5') + $matches, array());
if (!isset(($a = array('POST' => 0))[$requestMethod])) {
$allow += $a;
@ -149,6 +159,9 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
not_baz5:
// baz.baz6
if ('/' !== $pathinfo && '/' !== $pathinfo[-1]) {
break;
}
$ret = $this->mergeDefaults(array('_route' => 'baz.baz6') + $matches, array());
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
$allow += $a;
@ -159,10 +172,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
not_bazbaz6:
break;
case 161:
case 160:
$matches = array('foo' => $matches[1] ?? null);
// foo1
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
break;
}
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
$allow += $a;
@ -173,42 +189,52 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
not_foo1:
break;
case 205:
case 204:
$matches = array('foo1' => $matches[1] ?? null);
// foo2
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
break;
}
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
break;
case 280:
case 279:
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
// foo3
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
break;
}
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
break;
default:
$routes = array(
47 => array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null),
70 => array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null),
90 => array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null),
132 => array(array('_route' => 'quoter'), array('quoter'), null, null),
169 => array(array('_route' => 'bar1'), array('bar'), null, null),
182 => array(array('_route' => 'overridden'), array('var'), null, null),
213 => array(array('_route' => 'bar2'), array('bar1'), null, null),
249 => array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null),
288 => array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null),
310 => array(array('_route' => 'foo4'), array('foo'), null, null),
372 => array(array('_route' => 'route13'), array('var1', 'name'), null, null),
390 => array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null),
442 => array(array('_route' => 'route15'), array('name'), null, null),
490 => array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null),
511 => array(array('_route' => 'a'), array(), null, null),
532 => array(array('_route' => 'b'), array('var'), null, null),
550 => array(array('_route' => 'c'), array('var'), null, null),
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),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
@ -231,7 +257,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
return $ret;
}
if (550 === $m) {
if (549 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));

View File

@ -53,7 +53,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -65,30 +65,34 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
$regexList = array(
0 => '{^(?'
.'|/(en|fr)/(?'
.'|admin/post/(?'
.'|(*:33)'
.'|new(*:43)'
.'|(\\d+)(*:55)'
.'|(\\d+)/edit(*:72)'
.'|(\\d+)/delete(*:91)'
.')'
.'|blog/(?'
.'|(*:107)'
.'|rss\\.xml(*:123)'
.'|p(?'
.'|age/([^/]++)(*:147)'
.'|osts/([^/]++)(*:168)'
.'|admin/post(?'
.'|(*:32)'
.'|/(?'
.'|new(*:46)'
.'|(\\d+)(*:58)'
.'|(\\d+)/edit(*:75)'
.'|(\\d+)/delete(*:94)'
.')'
.')'
.'|blog(?'
.'|(*:110)'
.'|/(?'
.'|rss\\.xml(*:130)'
.'|p(?'
.'|age/([^/]++)(*:154)'
.'|osts/([^/]++)(*:175)'
.')'
.'|comments/(\\d+)/new(*:202)'
.'|search(*:216)'
.')'
.'|comments/(\\d+)/new(*:195)'
.'|search(*:209)'
.')'
.'|log(?'
.'|in(*:226)'
.'|out(*:237)'
.'|in(*:234)'
.'|out(*:245)'
.')'
.')'
.'|/(en|fr)?(*:256)'
.')$}sD',
.'|/(en|fr)?(*:264)'
.')(?:/?)$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -96,23 +100,27 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
33 => array(array('_route' => 'a', '_locale' => 'en'), array('_locale'), null, null),
43 => array(array('_route' => 'b', '_locale' => 'en'), array('_locale'), null, null),
55 => array(array('_route' => 'c', '_locale' => 'en'), array('_locale', 'id'), null, null),
72 => array(array('_route' => 'd', '_locale' => 'en'), array('_locale', 'id'), null, null),
91 => array(array('_route' => 'e', '_locale' => 'en'), array('_locale', 'id'), null, null),
107 => array(array('_route' => 'f', '_locale' => 'en'), array('_locale'), null, null),
123 => array(array('_route' => 'g', '_locale' => 'en'), array('_locale'), null, null),
147 => array(array('_route' => 'h', '_locale' => 'en'), array('_locale', 'page'), null, null),
168 => array(array('_route' => 'i', '_locale' => 'en'), array('_locale', 'page'), null, null),
195 => array(array('_route' => 'j', '_locale' => 'en'), array('_locale', 'id'), null, null),
209 => array(array('_route' => 'k', '_locale' => 'en'), array('_locale'), null, null),
226 => array(array('_route' => 'l', '_locale' => 'en'), array('_locale'), null, null),
237 => array(array('_route' => 'm', '_locale' => 'en'), array('_locale'), null, null),
256 => array(array('_route' => 'n', '_locale' => 'en'), array('_locale'), null, null),
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),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
return null;
}
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
@ -135,7 +143,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
return $ret;
}
if (256 === $m) {
if (264 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));

View File

@ -18,7 +18,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -45,7 +45,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.')'
.')'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -53,15 +53,19 @@ 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),
38 => array(array('_route' => 'r10'), array('foo'), null, null),
46 => array(array('_route' => 'r100'), array('foo'), null, null),
59 => array(array('_route' => 'r2'), array('foo'), null, null),
70 => array(array('_route' => 'r20'), array('foo'), null, null),
78 => array(array('_route' => 'r200'), array('foo'), null, null),
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),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {

View File

@ -18,7 +18,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
@ -35,7 +35,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.'|(*:56)'
.')'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -45,9 +45,15 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$matches = array('foo' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
// r1
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
break;
}
return $this->mergeDefaults(array('_route' => 'r1') + $matches, array());
// r2
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
break;
}
return $this->mergeDefaults(array('_route' => 'r2') + $matches, array());
break;

View File

@ -53,7 +53,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
@ -62,34 +62,38 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
default:
$routes = array(
'/test/baz' => array(array('_route' => 'baz'), null, null, null),
'/test/baz.html' => array(array('_route' => 'baz2'), null, null, null),
'/test/baz3/' => array(array('_route' => 'baz3'), null, null, null),
'/foofoo' => array(array('_route' => 'foofoo', 'def' => 'test'), null, null, null),
'/spa ce' => array(array('_route' => 'space'), null, null, null),
'/multi/new' => array(array('_route' => 'overridden2'), null, null, null),
'/multi/hey/' => array(array('_route' => 'hey'), null, null, null),
'/ababa' => array(array('_route' => 'ababa'), null, null, null),
'/route1' => array(array('_route' => 'route1'), 'a.example.com', null, null),
'/c2/route2' => array(array('_route' => 'route2'), 'a.example.com', null, null),
'/route4' => array(array('_route' => 'route4'), 'a.example.com', null, null),
'/c2/route3' => array(array('_route' => 'route3'), 'b.example.com', null, null),
'/route5' => array(array('_route' => 'route5'), 'c.example.com', null, null),
'/route6' => array(array('_route' => 'route6'), null, null, null),
'/route11' => array(array('_route' => 'route11'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null),
'/route12' => array(array('_route' => 'route12', 'var1' => 'val'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null),
'/route17' => array(array('_route' => 'route17'), null, null, null),
'/secure' => array(array('_route' => 'secure'), null, null, array('https' => 0)),
'/nonsecure' => array(array('_route' => 'nonsecure'), null, null, array('http' => 0)),
'/test/baz' => array(array('_route' => 'baz'), null, null, null, false),
'/test/baz.html' => array(array('_route' => 'baz2'), null, null, null, false),
'/test/baz3' => array(array('_route' => 'baz3'), null, null, null, true),
'/foofoo' => array(array('_route' => 'foofoo', 'def' => 'test'), null, null, null, false),
'/spa ce' => array(array('_route' => 'space'), null, null, null, false),
'/multi/new' => array(array('_route' => 'overridden2'), null, null, null, false),
'/multi/hey' => array(array('_route' => 'hey'), null, null, null, true),
'/ababa' => array(array('_route' => 'ababa'), null, null, null, false),
'/route1' => array(array('_route' => 'route1'), 'a.example.com', null, null, false),
'/c2/route2' => array(array('_route' => 'route2'), 'a.example.com', null, null, false),
'/route4' => array(array('_route' => 'route4'), 'a.example.com', null, null, false),
'/c2/route3' => array(array('_route' => 'route3'), 'b.example.com', null, null, false),
'/route5' => array(array('_route' => 'route5'), 'c.example.com', null, null, false),
'/route6' => array(array('_route' => 'route6'), null, null, null, false),
'/route11' => array(array('_route' => 'route11'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false),
'/route12' => array(array('_route' => 'route12', 'var1' => 'val'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false),
'/route17' => array(array('_route' => 'route17'), null, null, null, false),
'/secure' => array(array('_route' => 'secure'), null, null, array('https' => 0), false),
'/nonsecure' => array(array('_route' => 'nonsecure'), null, null, array('http' => 0), false),
);
if (!isset($routes[$pathinfo])) {
if (!isset($routes[$trimmedPathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
return null;
}
if ($requiredHost) {
if ('#' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) {
@ -125,57 +129,63 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
.'|/([^/]++)(*:70)'
.'|head/([^/]++)(*:90)'
.')'
.'|/test/([^/]++)/(?'
.'|(*:116)'
.'|/test/([^/]++)(?'
.'|(*:115)'
.')'
.'|/([\']+)(*:132)'
.'|/([\']+)(*:131)'
.'|/a/(?'
.'|b\'b/([^/]++)(?'
.'|(*:161)'
.'|(*:169)'
.'|(*:160)'
.'|(*:168)'
.')'
.'|(.*)(*:182)'
.'|(.*)(*:181)'
.'|b\'b/([^/]++)(?'
.'|(*:205)'
.'|(*:213)'
.'|(*:204)'
.'|(*:212)'
.')'
.')'
.'|/multi/hello(?:/([^/]++))?(*:249)'
.'|/multi/hello(?:/([^/]++))?(*:248)'
.'|/([^/]++)/b/([^/]++)(?'
.'|(*:280)'
.'|(*:288)'
.'|(*:279)'
.'|(*:287)'
.')'
.'|/aba/([^/]++)(*:310)'
.'|/aba/([^/]++)(*:309)'
.')|(?i:([^\\.]++)\\.example\\.com)\\.(?'
.'|/route1(?'
.'|3/([^/]++)(*:372)'
.'|4/([^/]++)(*:390)'
.'|3/([^/]++)(*:371)'
.'|4/([^/]++)(*:389)'
.')'
.')|(?i:c\\.example\\.com)\\.(?'
.'|/route15/([^/]++)(*:442)'
.'|/route15/([^/]++)(*:441)'
.')|(?:(?:[^./]*+\\.)++)(?'
.'|/route16/([^/]++)(*:490)'
.'|/route16/([^/]++)(*:489)'
.'|/a/(?'
.'|a\\.\\.\\.(*:511)'
.'|a\\.\\.\\.(*:510)'
.'|b/(?'
.'|([^/]++)(*:532)'
.'|c/([^/]++)(*:550)'
.'|([^/]++)(*:531)'
.'|c/([^/]++)(*:549)'
.')'
.')'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
case 116:
case 115:
$matches = array('foo' => $matches[1] ?? null);
// baz4
if ('/' !== $pathinfo && '/' !== $pathinfo[-1]) {
return null;
}
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
// baz5
if ('/' !== $pathinfo && '/' !== $pathinfo[-1]) {
return null;
}
$ret = $this->mergeDefaults(array('_route' => 'baz5') + $matches, array());
if (!isset(($a = array('POST' => 0))[$requestMethod])) {
$allow += $a;
@ -186,6 +196,9 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
not_baz5:
// baz.baz6
if ('/' !== $pathinfo && '/' !== $pathinfo[-1]) {
return null;
}
$ret = $this->mergeDefaults(array('_route' => 'baz.baz6') + $matches, array());
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
$allow += $a;
@ -196,10 +209,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
not_bazbaz6:
break;
case 161:
case 160:
$matches = array('foo' => $matches[1] ?? null);
// foo1
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
return null;
}
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
$allow += $a;
@ -210,42 +226,52 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
not_foo1:
break;
case 205:
case 204:
$matches = array('foo1' => $matches[1] ?? null);
// foo2
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
return null;
}
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
break;
case 280:
case 279:
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
// foo3
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
return null;
}
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
break;
default:
$routes = array(
47 => array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null),
70 => array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null),
90 => array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null),
132 => array(array('_route' => 'quoter'), array('quoter'), null, null),
169 => array(array('_route' => 'bar1'), array('bar'), null, null),
182 => array(array('_route' => 'overridden'), array('var'), null, null),
213 => array(array('_route' => 'bar2'), array('bar1'), null, null),
249 => array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null),
288 => array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null),
310 => array(array('_route' => 'foo4'), array('foo'), null, null),
372 => array(array('_route' => 'route13'), array('var1', 'name'), null, null),
390 => array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null),
442 => array(array('_route' => 'route15'), array('name'), null, null),
490 => array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null),
511 => array(array('_route' => 'a'), array(), null, null),
532 => array(array('_route' => 'b'), array('var'), null, null),
550 => array(array('_route' => 'c'), array('var'), null, null),
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),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
return null;
}
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
@ -268,7 +294,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
return $ret;
}
if (550 === $m) {
if (549 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));

View File

@ -18,7 +18,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -26,22 +26,29 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
case '/with-condition':
// with-condition
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
break;
}
if (($context->getMethod() == "GET")) {
return array('_route' => 'with-condition');
}
break;
default:
$routes = array(
'/rootprefix/test' => array(array('_route' => 'static'), null, null, null),
'/rootprefix/test' => array(array('_route' => 'static'), null, null, null, false),
);
if (!isset($routes[$pathinfo])) {
if (!isset($routes[$trimmedPathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
@ -62,7 +69,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$regexList = array(
0 => '{^(?'
.'|/rootprefix/([^/]++)(*:27)'
.')$}sD',
.')(?:/?)$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -70,10 +77,14 @@ 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),
27 => array(array('_route' => 'dynamic'), array('var'), null, null, false),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {

View File

@ -18,7 +18,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -26,9 +26,12 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
case '/put_and_post':
// put_and_post
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
break;
}
$ret = array('_route' => 'put_and_post');
if (!isset(($a = array('PUT' => 0, 'POST' => 1))[$requestMethod])) {
$allow += $a;
@ -38,6 +41,9 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
return $ret;
not_put_and_post:
// put_and_get_and_head
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
break;
}
$ret = array('_route' => 'put_and_get_and_head');
if (!isset(($a = array('PUT' => 0, 'GET' => 1, 'HEAD' => 2))[$canonicalMethod])) {
$allow += $a;
@ -49,16 +55,20 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
break;
default:
$routes = array(
'/just_head' => array(array('_route' => 'just_head'), null, array('HEAD' => 0), null),
'/head_and_get' => array(array('_route' => 'head_and_get'), null, array('HEAD' => 0, 'GET' => 1), null),
'/get_and_head' => array(array('_route' => 'get_and_head'), null, array('GET' => 0, 'HEAD' => 1), null),
'/post_and_head' => array(array('_route' => 'post_and_head'), null, array('POST' => 0, 'HEAD' => 1), null),
'/just_head' => array(array('_route' => 'just_head'), null, array('HEAD' => 0), null, false),
'/head_and_get' => array(array('_route' => 'head_and_get'), null, array('HEAD' => 0, 'GET' => 1), null, false),
'/get_and_head' => array(array('_route' => 'get_and_head'), null, array('GET' => 0, 'HEAD' => 1), null, false),
'/post_and_head' => array(array('_route' => 'post_and_head'), null, array('POST' => 0, 'HEAD' => 1), null, false),
);
if (!isset($routes[$pathinfo])) {
if (!isset($routes[$trimmedPathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {

View File

@ -53,7 +53,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -61,27 +61,31 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
default:
$routes = array(
'/a/11' => array(array('_route' => 'a_first'), null, null, null),
'/a/22' => array(array('_route' => 'a_second'), null, null, null),
'/a/333' => array(array('_route' => 'a_third'), null, null, null),
'/a/44/' => array(array('_route' => 'a_fourth'), null, null, null),
'/a/55/' => array(array('_route' => 'a_fifth'), null, null, null),
'/a/66/' => array(array('_route' => 'a_sixth'), null, null, null),
'/nested/group/a/' => array(array('_route' => 'nested_a'), null, null, null),
'/nested/group/b/' => array(array('_route' => 'nested_b'), null, null, null),
'/nested/group/c/' => array(array('_route' => 'nested_c'), null, null, null),
'/slashed/group/' => array(array('_route' => 'slashed_a'), null, null, null),
'/slashed/group/b/' => array(array('_route' => 'slashed_b'), null, null, null),
'/slashed/group/c/' => array(array('_route' => 'slashed_c'), null, null, null),
'/a/11' => array(array('_route' => 'a_first'), null, null, null, false),
'/a/22' => array(array('_route' => 'a_second'), null, null, null, false),
'/a/333' => array(array('_route' => 'a_third'), null, null, null, false),
'/a/44' => array(array('_route' => 'a_fourth'), null, null, null, true),
'/a/55' => array(array('_route' => 'a_fifth'), null, null, null, true),
'/a/66' => array(array('_route' => 'a_sixth'), null, null, null, true),
'/nested/group/a' => array(array('_route' => 'nested_a'), null, null, null, true),
'/nested/group/b' => array(array('_route' => 'nested_b'), null, null, null, true),
'/nested/group/c' => array(array('_route' => 'nested_c'), null, null, null, true),
'/slashed/group' => array(array('_route' => 'slashed_a'), null, null, null, true),
'/slashed/group/b' => array(array('_route' => 'slashed_b'), null, null, null, true),
'/slashed/group/c' => array(array('_route' => 'slashed_c'), null, null, null, true),
);
if (!isset($routes[$pathinfo])) {
if (!isset($routes[$trimmedPathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
return null;
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
@ -103,7 +107,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
0 => '{^(?'
.'|/([^/]++)(*:16)'
.'|/nested/([^/]++)(*:39)'
.')$}sD',
.')(?:/?)$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -111,11 +115,15 @@ 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),
39 => array(array('_route' => 'nested_wildcard'), array('param'), null, null),
16 => array(array('_route' => 'a_wildcard'), array('param'), null, null, false),
39 => array(array('_route' => 'nested_wildcard'), array('param'), null, null, false),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
return null;
}
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {

View File

@ -18,7 +18,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -26,23 +26,27 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
default:
$routes = array(
'/trailing/simple/no-methods/' => array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null),
'/trailing/simple/get-method/' => array(array('_route' => 'simple_trailing_slash_GET_method'), null, array('GET' => 0), null),
'/trailing/simple/head-method/' => array(array('_route' => 'simple_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null),
'/trailing/simple/post-method/' => array(array('_route' => 'simple_trailing_slash_POST_method'), null, array('POST' => 0), null),
'/not-trailing/simple/no-methods' => array(array('_route' => 'simple_not_trailing_slash_no_methods'), null, null, null),
'/not-trailing/simple/get-method' => array(array('_route' => 'simple_not_trailing_slash_GET_method'), null, array('GET' => 0), null),
'/not-trailing/simple/head-method' => array(array('_route' => 'simple_not_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null),
'/not-trailing/simple/post-method' => array(array('_route' => 'simple_not_trailing_slash_POST_method'), null, array('POST' => 0), null),
'/trailing/simple/no-methods' => array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null, true),
'/trailing/simple/get-method' => array(array('_route' => 'simple_trailing_slash_GET_method'), null, array('GET' => 0), null, true),
'/trailing/simple/head-method' => array(array('_route' => 'simple_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, true),
'/trailing/simple/post-method' => array(array('_route' => 'simple_trailing_slash_POST_method'), null, array('POST' => 0), null, true),
'/not-trailing/simple/no-methods' => array(array('_route' => 'simple_not_trailing_slash_no_methods'), null, null, null, false),
'/not-trailing/simple/get-method' => array(array('_route' => 'simple_not_trailing_slash_GET_method'), null, array('GET' => 0), null, false),
'/not-trailing/simple/head-method' => array(array('_route' => 'simple_not_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, false),
'/not-trailing/simple/post-method' => array(array('_route' => 'simple_not_trailing_slash_POST_method'), null, array('POST' => 0), null, false),
);
if (!isset($routes[$pathinfo])) {
if (!isset($routes[$trimmedPathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
@ -63,18 +67,18 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$regexList = array(
0 => '{^(?'
.'|/trailing/regex/(?'
.'|no\\-methods/([^/]++)/(*:47)'
.'|get\\-method/([^/]++)/(*:75)'
.'|head\\-method/([^/]++)/(*:104)'
.'|post\\-method/([^/]++)/(*:134)'
.'|no\\-methods/([^/]++)(*:46)'
.'|get\\-method/([^/]++)(*:73)'
.'|head\\-method/([^/]++)(*:101)'
.'|post\\-method/([^/]++)(*:130)'
.')'
.'|/not\\-trailing/regex/(?'
.'|no\\-methods/([^/]++)(*:187)'
.'|get\\-method/([^/]++)(*:215)'
.'|head\\-method/([^/]++)(*:244)'
.'|post\\-method/([^/]++)(*:273)'
.'|no\\-methods/([^/]++)(*:183)'
.'|get\\-method/([^/]++)(*:211)'
.'|head\\-method/([^/]++)(*:240)'
.'|post\\-method/([^/]++)(*:269)'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -82,17 +86,21 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
47 => array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null),
75 => array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null),
104 => array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null),
134 => array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null),
187 => array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null),
215 => array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null),
244 => array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null),
273 => array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null),
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),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
@ -115,7 +123,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
return $ret;
}
if (273 === $m) {
if (269 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));

View File

@ -53,7 +53,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -61,23 +61,27 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
switch ($trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo) {
default:
$routes = array(
'/trailing/simple/no-methods/' => array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null),
'/trailing/simple/get-method/' => array(array('_route' => 'simple_trailing_slash_GET_method'), null, array('GET' => 0), null),
'/trailing/simple/head-method/' => array(array('_route' => 'simple_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null),
'/trailing/simple/post-method/' => array(array('_route' => 'simple_trailing_slash_POST_method'), null, array('POST' => 0), null),
'/not-trailing/simple/no-methods' => array(array('_route' => 'simple_not_trailing_slash_no_methods'), null, null, null),
'/not-trailing/simple/get-method' => array(array('_route' => 'simple_not_trailing_slash_GET_method'), null, array('GET' => 0), null),
'/not-trailing/simple/head-method' => array(array('_route' => 'simple_not_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null),
'/not-trailing/simple/post-method' => array(array('_route' => 'simple_not_trailing_slash_POST_method'), null, array('POST' => 0), null),
'/trailing/simple/no-methods' => array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null, true),
'/trailing/simple/get-method' => array(array('_route' => 'simple_trailing_slash_GET_method'), null, array('GET' => 0), null, true),
'/trailing/simple/head-method' => array(array('_route' => 'simple_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, true),
'/trailing/simple/post-method' => array(array('_route' => 'simple_trailing_slash_POST_method'), null, array('POST' => 0), null, true),
'/not-trailing/simple/no-methods' => array(array('_route' => 'simple_not_trailing_slash_no_methods'), null, null, null, false),
'/not-trailing/simple/get-method' => array(array('_route' => 'simple_not_trailing_slash_GET_method'), null, array('GET' => 0), null, false),
'/not-trailing/simple/head-method' => array(array('_route' => 'simple_not_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, false),
'/not-trailing/simple/post-method' => array(array('_route' => 'simple_not_trailing_slash_POST_method'), null, array('POST' => 0), null, false),
);
if (!isset($routes[$pathinfo])) {
if (!isset($routes[$trimmedPathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$trimmedPathinfo];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
return null;
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
@ -98,18 +102,18 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
$regexList = array(
0 => '{^(?'
.'|/trailing/regex/(?'
.'|no\\-methods/([^/]++)/(*:47)'
.'|get\\-method/([^/]++)/(*:75)'
.'|head\\-method/([^/]++)/(*:104)'
.'|post\\-method/([^/]++)/(*:134)'
.'|no\\-methods/([^/]++)(*:46)'
.'|get\\-method/([^/]++)(*:73)'
.'|head\\-method/([^/]++)(*:101)'
.'|post\\-method/([^/]++)(*:130)'
.')'
.'|/not\\-trailing/regex/(?'
.'|no\\-methods/([^/]++)(*:187)'
.'|get\\-method/([^/]++)(*:215)'
.'|head\\-method/([^/]++)(*:244)'
.'|post\\-method/([^/]++)(*:273)'
.'|no\\-methods/([^/]++)(*:183)'
.'|get\\-method/([^/]++)(*:211)'
.'|head\\-method/([^/]++)(*:240)'
.'|post\\-method/([^/]++)(*:269)'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
foreach ($regexList as $offset => $regex) {
@ -117,17 +121,21 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
47 => array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null),
75 => array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null),
104 => array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null),
134 => array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null),
187 => array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null),
215 => array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null),
244 => array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null),
273 => array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null),
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),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
return null;
}
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
@ -150,7 +158,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
return $ret;
}
if (273 === $m) {
if (269 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));

View File

@ -18,7 +18,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
@ -30,13 +30,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,12 +44,16 @@ 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),
22 => array(array('_route' => 'b'), array('a'), null, null),
33 => array(array('_route' => 'c'), array('a'), null, null),
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),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash) = $routes[$m];
if ('/' !== $pathinfo && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
break;
}
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {

View File

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

View File

@ -141,6 +141,25 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$this->assertSame(array('_route' => 'foo'), $matcher->match('/foo'));
}
public function testFallbackPage()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/'));
$coll->add('bar', new Route('/{name}'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo')->will($this->returnValue(array('_route' => 'foo')));
$this->assertSame(array('_route' => 'foo'), $matcher->match('/foo'));
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo'));
$coll->add('bar', new Route('/{name}/'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo', 'foo')->will($this->returnValue(array('_route' => 'foo')));
$this->assertSame(array('_route' => 'foo'), $matcher->match('/foo/'));
}
public function testMissingTrailingSlashAndScheme()
{
$coll = new RouteCollection();