diff --git a/lib/routing/sfPatternRouting.class.php b/lib/routing/sfPatternRouting.class.php index b14c74d5d5..12c67c01f1 100644 --- a/lib/routing/sfPatternRouting.class.php +++ b/lib/routing/sfPatternRouting.class.php @@ -58,9 +58,16 @@ public function initialize(sfEventDispatcher $dispatcher, sfCache $cache = null, $options['variable_regex'] = '[\w\d_]+'; } - $options['variable_prefix_regex'] = '(?:'.implode('|', array_map(create_function('$a', 'return preg_quote($a, \'#\');'), $options['variable_prefixes'])).')'; - $options['segment_separators_regex'] = '(?:'.implode('|', array_map(create_function('$a', 'return preg_quote($a, \'#\');'), $options['segment_separators'])).')'; - $options['variable_content_regex'] = '[^'.implode('', array_map(create_function('$a', 'return str_replace(\'-\', \'\-\', preg_quote($a, \'#\'));'), $options['segment_separators'])).']+'; + $quote = function ($a) { + return preg_quote($a, '#'); + }; + $replace = function ($a) { + return str_replace('-', '\-', preg_quote($a, '#')); + }; + + $options['variable_prefix_regex'] = '(?:'.implode('|', array_map($quote, $options['variable_prefixes'])).')'; + $options['segment_separators_regex'] = '(?:'.implode('|', array_map($quote, $options['segment_separators'])).')'; + $options['variable_content_regex'] = '[^'.implode('', array_map($replace, $options['segment_separators'])).']+'; if (!isset($options['load_configuration'])) { diff --git a/test/lib/routing/sfPatternRoutingTest.php b/test/lib/routing/sfPatternRoutingTest.php new file mode 100644 index 0000000000..f4bc23a1ba --- /dev/null +++ b/test/lib/routing/sfPatternRoutingTest.php @@ -0,0 +1,33 @@ +connect('hello_world', '/hello/world'); + $router->connect('hello_name', '/hello/:name'); + $router->connect('default', '/:module/:action/*'); + + $result = $router->findRoute($url); + self::assertSame($expected_name, $result['name']); + self::assertSame($expected_params, $result['parameters']); + } + + public function findRouteProvider() + { + return [ + ['/hello/world', 'hello_world', ['module' => 'default', 'action' => 'index']], + ['/hello/henk', 'hello_name', ['module' => 'default', 'action' => 'index', 'name' => 'henk']], + ['/a/b', 'default', ['module' => 'a', 'action' => 'b']], + ['/a/b/c/d', 'default', ['c' => 'd', 'module' => 'a', 'action' => 'b']], + ]; + } +}