From 9619c7dade0db54d9171dcc26c7218f94ec45e9e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 21 Feb 2011 10:25:22 +0100 Subject: [PATCH] [Routing] removing the routing hack where we add a / at the beginning if it does not exist --- src/Symfony/Component/Routing/Matcher/UrlMatcher.php | 2 +- .../Component/Routing/Matcher/UrlMatcherTest.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index d1f42eb5fe..10eb8f9a0c 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -102,7 +102,7 @@ class UrlMatcher implements UrlMatcherInterface { // ensure that the URL starts with a / if ('/' !== substr($url, 0, 1)) { - $url = '/'.$url; + throw new \InvalidArgumentException(sprintf('URL "%s" is not valid (it does not start with a /).', $url)); } // remove the query string diff --git a/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php b/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php index 3f0a75247b..c2bcb5ef57 100644 --- a/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php +++ b/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php @@ -24,12 +24,19 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase $matcher = new UrlMatcherForTests($collection, array(), array()); - $this->assertEquals('/', $matcher->normalizeUrl(''), '->normalizeUrl() adds a / at the beginning of the URL if needed'); - $this->assertEquals('/foo', $matcher->normalizeUrl('foo'), '->normalizeUrl() adds a / at the beginning of the URL if needed'); $this->assertEquals('/foo', $matcher->normalizeUrl('/foo?foo=bar'), '->normalizeUrl() removes the query string'); $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