Skip to content

Commit 828c95d

Browse files
Tobionfabpot
authored andcommitted
[Routing] removed restriction of route names
1 parent fae3e35 commit 828c95d

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

src/Symfony/Component/Routing/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ CHANGELOG
2020
check on URL generation completely by calling `setStrictRequirements(null)`. It
2121
improves performance in production environment as you should know that params always
2222
pass the requirements (otherwise it would break your link anyway).
23+
* There is no restriction on the route name anymore. So non-alphanumeric characters
24+
are now also allowed.
2325

2426
2.1.0
2527
-----

src/Symfony/Component/Routing/RouteCollection.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,10 @@ public function count()
112112
* @param string $name The route name
113113
* @param Route $route A Route instance
114114
*
115-
* @throws \InvalidArgumentException When route name contains non valid characters
116-
*
117115
* @api
118116
*/
119117
public function add($name, Route $route)
120118
{
121-
if (!preg_match('/^[a-z0-9A-Z_.]+$/', $name)) {
122-
throw new \InvalidArgumentException(sprintf('The provided route name "%s" contains non valid characters. A route name must only contain digits (0-9), letters (a-z and A-Z), underscores (_) and dots (.).', $name));
123-
}
124-
125119
$this->remove($name);
126120

127121
$this->routes[$name] = $route;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"#$péß^a|":
2+
pattern: "true"

src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,13 @@ public function testQueryParamSameAsDefault()
294294
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
295295
}
296296

297+
public function testGenerateWithSpecialRouteName()
298+
{
299+
$routes = $this->getRoutes('$péß^a|', new Route('/bar'));
300+
301+
$this->assertSame('/app.php/bar', $this->getGenerator($routes)->generate('$péß^a|'));
302+
}
303+
297304
public function testUrlEncoding()
298305
{
299306
// This tests the encoding of reserved characters that are used for delimiting of URI components (defined in RFC 3986)

src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ public function testLoadThrowsExceptionWhenIncomplete()
7979
$loader->load('incomplete.yml');
8080
}
8181

82+
public function testLoadSpecialRouteName()
83+
{
84+
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
85+
$routeCollection = $loader->load('special_route_name.yml');
86+
$route = $routeCollection->get('#$péß^a|');
87+
88+
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
89+
$this->assertSame('/true', $route->getPattern());
90+
}
91+
8292
public function testLoadWithPattern()
8393
{
8494
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ public function testMatchWithDynamicPrefix()
158158
$this->assertEquals(array('_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'), $matcher->match('/fr/b/foo'));
159159
}
160160

161+
public function testMatchSpecialRouteName()
162+
{
163+
$collection = new RouteCollection();
164+
$collection->add('$péß^a|', new Route('/bar'));
165+
166+
$matcher = new UrlMatcher($collection, new RequestContext());
167+
$this->assertEquals(array('_route' => '$péß^a|'), $matcher->match('/bar'));
168+
}
169+
161170
public function testMatchNonAlpha()
162171
{
163172
$collection = new RouteCollection();

src/Symfony/Component/Routing/Tests/RouteCollectionTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ public function testRoute()
2727
$this->assertNull($collection->get('bar'), '->get() returns null if a route does not exist');
2828
}
2929

30-
/**
31-
* @expectedException \InvalidArgumentException
32-
*/
33-
public function testAddInvalidRoute()
34-
{
35-
$collection = new RouteCollection();
36-
$route = new Route('/foo');
37-
$collection->add('f o o', $route);
38-
}
39-
4030
public function testOverriddenRoute()
4131
{
4232
$collection = new RouteCollection();

0 commit comments

Comments
 (0)