Added PCRE_DOTALL modifier to RouteCompiler to allow urlencoded linefeed in route parameters.
This commit is contained in:
parent
b8e5a155e4
commit
ae3aded83f
@ -96,7 +96,7 @@ class RouteCompiler implements RouteCompilerInterface
|
||||
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
|
||||
);
|
||||
|
@ -160,6 +160,15 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
|
||||
$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()
|
||||
{
|
||||
@ -179,4 +188,4 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
|
||||
} catch (ResourceNotFoundException $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -36,14 +36,14 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
|
||||
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'),
|
||||
)),
|
||||
@ -51,7 +51,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
|
||||
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'),
|
||||
)),
|
||||
@ -59,7 +59,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
|
||||
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'),
|
||||
@ -68,7 +68,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
|
||||
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'),
|
||||
@ -77,7 +77,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
|
||||
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'),
|
||||
@ -86,16 +86,16 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
|
||||
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'),
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user