Skip to content

Commit

Permalink
[Routing] made an empty path info to redirect to / (as for any other …
Browse files Browse the repository at this point in the history
…route that ends with a /)
  • Loading branch information
fabpot committed Feb 26, 2011
1 parent f46c6f7 commit e16c666
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 16 deletions.
Expand Up @@ -70,7 +70,7 @@ public function dump(array $options = array())
$regexes[] = sprintf("%sRewriteCond %%{PATH_INFO} %s\nRewriteRule .* %s [QSA,L,%s]", $conditions, $regex, $options['script_name'], $variables);

// add redirect for missing trailing slash
if ('/$' === substr($regex, -2) && '^/$' !== $regex) {
if ('/$' === substr($regex, -2)) {
$regexes[count($regexes)-1] .= sprintf("\nRewriteCond %%{PATH_INFO} %s\nRewriteRule .* /$0/ [QSA,L,R=301]", substr($regex, 0, -2).'$');
}
}
Expand Down
Expand Up @@ -62,7 +62,7 @@ protected function addMatcher()

$hasTrailingSlash = false;
if (!count($compiledRoute->getVariables()) && false !== preg_match('#^(.)\^(?P<url>.*?)\$\1#', $compiledRoute->getRegex(), $m)) {
if (substr($m['url'], -1) === '/' && $m['url'] !== '/') {
if (substr($m['url'], -1) === '/') {
$conditions[] = sprintf("rtrim(\$url, '/') === '%s'", rtrim(str_replace('\\', '', $m['url']), '/'));
$hasTrailingSlash = true;
} else {
Expand Down
5 changes: 0 additions & 5 deletions src/Symfony/Component/Routing/Matcher/UrlMatcher.php
Expand Up @@ -101,11 +101,6 @@ protected function mergeDefaults($params, $defaults)

protected function normalizeUrl($url)
{
// ensure that the URL starts with a /
if ('/' !== substr($url, 0, 1)) {
throw new \InvalidArgumentException(sprintf('URL "%s" is not valid (it does not start with a /).', $url));
}

// remove the query string
if (false !== $pos = strpos($url, '?')) {
$url = substr($url, 0, $pos);
Expand Down
Expand Up @@ -28,15 +28,6 @@ public function testNormalizeUrl()
$this->assertEquals('/foo/bar', $matcher->normalizeUrl('/foo//bar'), '->normalizeUrl() removes duplicated /');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testNormalizeUrlThrowsAnExceptionIfTheUrlIsInvalid()
{
$matcher = new UrlMatcherForTests(new RouteCollection(), array(), array());
$matcher->normalizeUrl('');
}

public function testMatch()
{
// test the patterns are matched are parameters are returned
Expand Down

0 comments on commit e16c666

Please sign in to comment.