Skip to content

Commit 9619c7d

Browse files
committed
[Routing] removing the routing hack where we add a / at the beginning if it does not exist
1 parent 52f4d81 commit 9619c7d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Symfony/Component/Routing/Matcher/UrlMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected function normalizeUrl($url)
102102
{
103103
// ensure that the URL starts with a /
104104
if ('/' !== substr($url, 0, 1)) {
105-
$url = '/'.$url;
105+
throw new \InvalidArgumentException(sprintf('URL "%s" is not valid (it does not start with a /).', $url));
106106
}
107107

108108
// remove the query string

tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ public function testNormalizeUrl()
2424

2525
$matcher = new UrlMatcherForTests($collection, array(), array());
2626

27-
$this->assertEquals('/', $matcher->normalizeUrl(''), '->normalizeUrl() adds a / at the beginning of the URL if needed');
28-
$this->assertEquals('/foo', $matcher->normalizeUrl('foo'), '->normalizeUrl() adds a / at the beginning of the URL if needed');
2927
$this->assertEquals('/foo', $matcher->normalizeUrl('/foo?foo=bar'), '->normalizeUrl() removes the query string');
3028
$this->assertEquals('/foo/bar', $matcher->normalizeUrl('/foo//bar'), '->normalizeUrl() removes duplicated /');
3129
}
3230

31+
/**
32+
* @expectedException \InvalidArgumentException
33+
*/
34+
public function testNormalizeUrlThrowsAnExceptionIfTheUrlIsInvalid()
35+
{
36+
$matcher = new UrlMatcherForTests(new RouteCollection(), array(), array());
37+
$matcher->normalizeUrl('');
38+
}
39+
3340
public function testMatch()
3441
{
3542
// test the patterns are matched are parameters are returned

0 commit comments

Comments
 (0)