Skip to content

Commit

Permalink
Added PCRE_DOTALL modifier to RouteCompiler to allow urlencoded linef…
Browse files Browse the repository at this point in the history
…eed in route parameters.
  • Loading branch information
geezmo committed Sep 23, 2011
1 parent b8e5a15 commit ae3aded
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/RouteCompiler.php
Expand Up @@ -96,7 +96,7 @@ public function compile(Route $route)
return new CompiledRoute(
$route,
'text' === $tokens[0][0] ? $tokens[0][1] : '',
sprintf("#^\n%s$#x", $regex),
sprintf("#^\n%s$#xs", $regex),
array_reverse($tokens),
$variables
);
Expand Down
11 changes: 10 additions & 1 deletion tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php
Expand Up @@ -160,6 +160,15 @@ public function testMatchNonAlpha()
$this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.urlencode($chars).'/bar'));
$this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.strtr($chars, array('%' => '%25', '+' => '%2B')).'/bar'));
}

public function testMatchWithDotMetacharacterInRequirements()
{
$collection = new RouteCollection();
$collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '.+')));

$matcher = new UrlMatcher($collection, new RequestContext(), array());
$this->assertEquals(array('_route' => 'foo', 'foo' => "\n"), $matcher->match('/'.urlencode("\n").'/bar'), 'linefeed character is matched');
}

public function testMatchRegression()
{
Expand All @@ -179,4 +188,4 @@ public function testMatchRegression()
} catch (ResourceNotFoundException $e) {
}
}
}
}
18 changes: 9 additions & 9 deletions tests/Symfony/Tests/Component/Routing/RouteCompilerTest.php
Expand Up @@ -36,30 +36,30 @@ public function provideCompileData()
array(
'Static route',
array('/foo'),
'/foo', '#^/foo$#x', array(), array(
'/foo', '#^/foo$#xs', array(), array(
array('text', '/foo'),
)),

array(
'Route with a variable',
array('/foo/{bar}'),
'/foo', '#^/foo/(?P<bar>[^/]+?)$#x', array('bar'), array(
'/foo', '#^/foo/(?P<bar>[^/]+?)$#xs', array('bar'), array(
array('variable', '/', '[^/]+?', 'bar'),
array('text', '/foo'),
)),

array(
'Route with a variable that has a default value',
array('/foo/{bar}', array('bar' => 'bar')),
'/foo', '#^/foo(?:/(?P<bar>[^/]+?))?$#x', array('bar'), array(
'/foo', '#^/foo(?:/(?P<bar>[^/]+?))?$#xs', array('bar'), array(
array('variable', '/', '[^/]+?', 'bar'),
array('text', '/foo'),
)),

array(
'Route with several variables',
array('/foo/{bar}/{foobar}'),
'/foo', '#^/foo/(?P<bar>[^/]+?)/(?P<foobar>[^/]+?)$#x', array('bar', 'foobar'), array(
'/foo', '#^/foo/(?P<bar>[^/]+?)/(?P<foobar>[^/]+?)$#xs', array('bar', 'foobar'), array(
array('variable', '/', '[^/]+?', 'foobar'),
array('variable', '/', '[^/]+?', 'bar'),
array('text', '/foo'),
Expand All @@ -68,7 +68,7 @@ public function provideCompileData()
array(
'Route with several variables that have default values',
array('/foo/{bar}/{foobar}', array('bar' => 'bar', 'foobar' => '')),
'/foo', '#^/foo(?:/(?P<bar>[^/]+?)(?:/(?P<foobar>[^/]+?))?)?$#x', array('bar', 'foobar'), array(
'/foo', '#^/foo(?:/(?P<bar>[^/]+?)(?:/(?P<foobar>[^/]+?))?)?$#xs', array('bar', 'foobar'), array(
array('variable', '/', '[^/]+?', 'foobar'),
array('variable', '/', '[^/]+?', 'bar'),
array('text', '/foo'),
Expand All @@ -77,7 +77,7 @@ public function provideCompileData()
array(
'Route with several variables but some of them have no default values',
array('/foo/{bar}/{foobar}', array('bar' => 'bar')),
'/foo', '#^/foo/(?P<bar>[^/]+?)/(?P<foobar>[^/]+?)$#x', array('bar', 'foobar'), array(
'/foo', '#^/foo/(?P<bar>[^/]+?)/(?P<foobar>[^/]+?)$#xs', array('bar', 'foobar'), array(
array('variable', '/', '[^/]+?', 'foobar'),
array('variable', '/', '[^/]+?', 'bar'),
array('text', '/foo'),
Expand All @@ -86,16 +86,16 @@ public function provideCompileData()
array(
'Route with an optional variable as the first segment',
array('/{bar}', array('bar' => 'bar')),
'', '#^/(?:(?P<bar>[^/]+?))?$#x', array('bar'), array(
'', '#^/(?:(?P<bar>[^/]+?))?$#xs', array('bar'), array(
array('variable', '/', '[^/]+?', 'bar'),
)),

array(
'Route with an optional variable as the first segment with requirements',
array('/{bar}', array('bar' => 'bar'), array('bar' => '(foo|bar)')),
'', '#^/(?:(?P<bar>(foo|bar)))?$#x', array('bar'), array(
'', '#^/(?:(?P<bar>(foo|bar)))?$#xs', array('bar'), array(
array('variable', '/', '(foo|bar)', 'bar'),
)),
);
}
}
}

0 comments on commit ae3aded

Please sign in to comment.