Skip to content

Commit

Permalink
[Routing] removed restriction of route names
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion authored and fabpot committed Nov 28, 2012
1 parent fae3e35 commit 828c95d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/Symfony/Component/Routing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ CHANGELOG
check on URL generation completely by calling `setStrictRequirements(null)`. It
improves performance in production environment as you should know that params always
pass the requirements (otherwise it would break your link anyway).
* There is no restriction on the route name anymore. So non-alphanumeric characters
are now also allowed.

2.1.0
-----
Expand Down
6 changes: 0 additions & 6 deletions src/Symfony/Component/Routing/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,10 @@ public function count()
* @param string $name The route name
* @param Route $route A Route instance
*
* @throws \InvalidArgumentException When route name contains non valid characters
*
* @api
*/
public function add($name, Route $route)
{
if (!preg_match('/^[a-z0-9A-Z_.]+$/', $name)) {
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));
}

$this->remove($name);

$this->routes[$name] = $route;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"#$péß^a|":
pattern: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ public function testQueryParamSameAsDefault()
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
}

public function testGenerateWithSpecialRouteName()
{
$routes = $this->getRoutes('$péß^a|', new Route('/bar'));

$this->assertSame('/app.php/bar', $this->getGenerator($routes)->generate('$péß^a|'));
}

public function testUrlEncoding()
{
// This tests the encoding of reserved characters that are used for delimiting of URI components (defined in RFC 3986)
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ public function testLoadThrowsExceptionWhenIncomplete()
$loader->load('incomplete.yml');
}

public function testLoadSpecialRouteName()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('special_route_name.yml');
$route = $routeCollection->get('#$péß^a|');

$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
$this->assertSame('/true', $route->getPattern());
}

public function testLoadWithPattern()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ public function testMatchWithDynamicPrefix()
$this->assertEquals(array('_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'), $matcher->match('/fr/b/foo'));
}

public function testMatchSpecialRouteName()
{
$collection = new RouteCollection();
$collection->add('$péß^a|', new Route('/bar'));

$matcher = new UrlMatcher($collection, new RequestContext());
$this->assertEquals(array('_route' => '$péß^a|'), $matcher->match('/bar'));
}

public function testMatchNonAlpha()
{
$collection = new RouteCollection();
Expand Down
10 changes: 0 additions & 10 deletions src/Symfony/Component/Routing/Tests/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ public function testRoute()
$this->assertNull($collection->get('bar'), '->get() returns null if a route does not exist');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testAddInvalidRoute()
{
$collection = new RouteCollection();
$route = new Route('/foo');
$collection->add('f o o', $route);
}

public function testOverriddenRoute()
{
$collection = new RouteCollection();
Expand Down

0 comments on commit 828c95d

Please sign in to comment.