diff --git a/src/Symfony/Component/Routing/RouteCompiler.php b/src/Symfony/Component/Routing/RouteCompiler.php index e9ed0b6333..5d35663571 100644 --- a/src/Symfony/Component/Routing/RouteCompiler.php +++ b/src/Symfony/Component/Routing/RouteCompiler.php @@ -51,7 +51,7 @@ class RouteCompiler implements RouteCompilerInterface // Use the character following the variable as the separator when available // Use the character preceding the variable otherwise $separator = $pos !== $len ? $pattern[$pos] : $match[0][0][0]; - $regexp = sprintf('[^%s]+?', preg_quote($separator, self::REGEX_DELIMITER)); + $regexp = sprintf('[^%s]+', preg_quote($separator, self::REGEX_DELIMITER)); } $tokens[] = array('variable', $match[0][0][0], $regexp, $var); diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.apache b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.apache index a937998089..25f6060fdd 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.apache +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.apache @@ -7,17 +7,17 @@ RewriteCond %{REQUEST_URI} ^/foo/(baz|symfony)$ RewriteRule .* app.php [QSA,L,E=_ROUTING__route:foo,E=_ROUTING_bar:%1,E=_ROUTING_def:test] # bar -RewriteCond %{REQUEST_URI} ^/bar/([^/]+?)$ +RewriteCond %{REQUEST_URI} ^/bar/([^/]+)$ RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [NC] RewriteRule .* - [S=1,E=_ROUTING__allow_GET:1,E=_ROUTING__allow_HEAD:1] -RewriteCond %{REQUEST_URI} ^/bar/([^/]+?)$ +RewriteCond %{REQUEST_URI} ^/bar/([^/]+)$ RewriteRule .* app.php [QSA,L,E=_ROUTING__route:bar,E=_ROUTING_foo:%1] # baragain -RewriteCond %{REQUEST_URI} ^/baragain/([^/]+?)$ +RewriteCond %{REQUEST_URI} ^/baragain/([^/]+)$ RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)$ [NC] RewriteRule .* - [S=1,E=_ROUTING__allow_GET:1,E=_ROUTING__allow_POST:1,E=_ROUTING__allow_HEAD:1] -RewriteCond %{REQUEST_URI} ^/baragain/([^/]+?)$ +RewriteCond %{REQUEST_URI} ^/baragain/([^/]+)$ RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baragain,E=_ROUTING_foo:%1] # baz @@ -35,25 +35,25 @@ RewriteCond %{REQUEST_URI} ^/test/baz3/$ RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baz3] # baz4 -RewriteCond %{REQUEST_URI} ^/test/([^/]+?)$ +RewriteCond %{REQUEST_URI} ^/test/([^/]+)$ RewriteRule .* $0/ [QSA,L,R=301] -RewriteCond %{REQUEST_URI} ^/test/([^/]+?)/$ +RewriteCond %{REQUEST_URI} ^/test/([^/]+)/$ RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baz4,E=_ROUTING_foo:%1] # baz5 -RewriteCond %{REQUEST_URI} ^/test/([^/]+?)/$ +RewriteCond %{REQUEST_URI} ^/test/([^/]+)/$ RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [NC] RewriteRule .* - [S=2,E=_ROUTING__allow_GET:1,E=_ROUTING__allow_HEAD:1] -RewriteCond %{REQUEST_URI} ^/test/([^/]+?)$ +RewriteCond %{REQUEST_URI} ^/test/([^/]+)$ RewriteRule .* $0/ [QSA,L,R=301] -RewriteCond %{REQUEST_URI} ^/test/([^/]+?)/$ +RewriteCond %{REQUEST_URI} ^/test/([^/]+)/$ RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baz5,E=_ROUTING_foo:%1] # baz5unsafe -RewriteCond %{REQUEST_URI} ^/testunsafe/([^/]+?)/$ +RewriteCond %{REQUEST_URI} ^/testunsafe/([^/]+)/$ RewriteCond %{REQUEST_METHOD} !^(POST)$ [NC] RewriteRule .* - [S=1,E=_ROUTING__allow_POST:1] -RewriteCond %{REQUEST_URI} ^/testunsafe/([^/]+?)/$ +RewriteCond %{REQUEST_URI} ^/testunsafe/([^/]+)/$ RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baz5unsafe,E=_ROUTING_foo:%1] # baz6 diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php index 2c764d0df3..8141b92242 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php @@ -31,7 +31,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // bar - if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?[^/]+)$#s', $pathinfo, $matches)) { if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { $allow = array_merge($allow, array('GET', 'HEAD')); goto not_bar; @@ -42,7 +42,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher not_bar: // barhead - if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?[^/]+)$#s', $pathinfo, $matches)) { if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { $allow = array_merge($allow, array('GET', 'HEAD')); goto not_barhead; @@ -68,13 +68,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // baz4 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+)/$#s', $pathinfo, $matches)) { $matches['_route'] = 'baz4'; return $matches; } // baz5 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+)/$#s', $pathinfo, $matches)) { if ($this->context->getMethod() != 'POST') { $allow[] = 'POST'; goto not_baz5; @@ -85,7 +85,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher not_baz5: // baz.baz6 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+)/$#s', $pathinfo, $matches)) { if ($this->context->getMethod() != 'PUT') { $allow[] = 'PUT'; goto not_bazbaz6; @@ -114,13 +114,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/a')) { if (0 === strpos($pathinfo, '/a/b\'b')) { // foo1 - if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo1'; return $matches; } // bar1 - if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar1'; return $matches; } @@ -135,13 +135,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/a/b\'b')) { // foo2 - if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo2'; return $matches; } // bar2 - if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar2'; return $matches; } @@ -152,7 +152,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/multi')) { // helloWorld - if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?[^/]+?))?$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?[^/]+))?$#s', $pathinfo, $matches)) { return array_merge($this->mergeDefaults($matches, array ( 'who' => 'World!',)), array('_route' => 'helloWorld')); } @@ -169,13 +169,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // foo3 - if (preg_match('#^/(?<_locale>[^/]+?)/b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/(?<_locale>[^/]+)/b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo3'; return $matches; } // bar3 - if (preg_match('#^/(?<_locale>[^/]+?)/b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/(?<_locale>[^/]+)/b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar3'; return $matches; } @@ -186,7 +186,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // foo4 - if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo4'; return $matches; } @@ -199,13 +199,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/a/b')) { // b - if (preg_match('#^/a/b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'b'; return $matches; } // c - if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'c'; return $matches; } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php index 4b9af5c5a1..822b715833 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php @@ -31,7 +31,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } // bar - if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?[^/]+)$#s', $pathinfo, $matches)) { if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { $allow = array_merge($allow, array('GET', 'HEAD')); goto not_bar; @@ -42,7 +42,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec not_bar: // barhead - if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?[^/]+)$#s', $pathinfo, $matches)) { if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { $allow = array_merge($allow, array('GET', 'HEAD')); goto not_barhead; @@ -71,7 +71,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } // baz4 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/?$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+)/?$#s', $pathinfo, $matches)) { if (substr($pathinfo, -1) !== '/') { return $this->redirect($pathinfo.'/', 'baz4'); } @@ -80,7 +80,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } // baz5 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+)/$#s', $pathinfo, $matches)) { if ($this->context->getMethod() != 'POST') { $allow[] = 'POST'; goto not_baz5; @@ -91,7 +91,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec not_baz5: // baz.baz6 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+)/$#s', $pathinfo, $matches)) { if ($this->context->getMethod() != 'PUT') { $allow[] = 'PUT'; goto not_bazbaz6; @@ -120,13 +120,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/a')) { if (0 === strpos($pathinfo, '/a/b\'b')) { // foo1 - if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo1'; return $matches; } // bar1 - if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar1'; return $matches; } @@ -141,13 +141,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/a/b\'b')) { // foo2 - if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo2'; return $matches; } // bar2 - if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar2'; return $matches; } @@ -158,7 +158,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/multi')) { // helloWorld - if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?[^/]+?))?$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?[^/]+))?$#s', $pathinfo, $matches)) { return array_merge($this->mergeDefaults($matches, array ( 'who' => 'World!',)), array('_route' => 'helloWorld')); } @@ -178,13 +178,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } // foo3 - if (preg_match('#^/(?<_locale>[^/]+?)/b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/(?<_locale>[^/]+)/b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo3'; return $matches; } // bar3 - if (preg_match('#^/(?<_locale>[^/]+?)/b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/(?<_locale>[^/]+)/b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar3'; return $matches; } @@ -195,7 +195,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } // foo4 - if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo4'; return $matches; } @@ -208,13 +208,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/a/b')) { // b - if (preg_match('#^/a/b/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'b'; return $matches; } // c - if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'c'; return $matches; } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php index 3373931ba6..4015481661 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php @@ -32,7 +32,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // dynamic - if (preg_match('#^/rootprefix/(?[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/rootprefix/(?[^/]+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'dynamic'; return $matches; } diff --git a/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php b/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php index 793a04e240..c2299975d2 100644 --- a/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php @@ -43,51 +43,51 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase array( 'Route with a variable', array('/foo/{bar}'), - '/foo', '#^/foo/(?[^/]+?)$#s', array('bar'), array( - array('variable', '/', '[^/]+?', 'bar'), + '/foo', '#^/foo/(?[^/]+)$#s', 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(?:/(?[^/]+?))?$#s', array('bar'), array( - array('variable', '/', '[^/]+?', 'bar'), + '/foo', '#^/foo(?:/(?[^/]+))?$#s', array('bar'), array( + array('variable', '/', '[^/]+', 'bar'), array('text', '/foo'), )), array( 'Route with several variables', array('/foo/{bar}/{foobar}'), - '/foo', '#^/foo/(?[^/]+?)/(?[^/]+?)$#s', array('bar', 'foobar'), array( - array('variable', '/', '[^/]+?', 'foobar'), - array('variable', '/', '[^/]+?', 'bar'), + '/foo', '#^/foo/(?[^/]+)/(?[^/]+)$#s', array('bar', 'foobar'), array( + array('variable', '/', '[^/]+', 'foobar'), + array('variable', '/', '[^/]+', 'bar'), array('text', '/foo'), )), array( 'Route with several variables that have default values', array('/foo/{bar}/{foobar}', array('bar' => 'bar', 'foobar' => '')), - '/foo', '#^/foo(?:/(?[^/]+?)(?:/(?[^/]+?))?)?$#s', array('bar', 'foobar'), array( - array('variable', '/', '[^/]+?', 'foobar'), - array('variable', '/', '[^/]+?', 'bar'), + '/foo', '#^/foo(?:/(?[^/]+)(?:/(?[^/]+))?)?$#s', array('bar', 'foobar'), array( + array('variable', '/', '[^/]+', 'foobar'), + array('variable', '/', '[^/]+', 'bar'), array('text', '/foo'), )), array( 'Route with several variables but some of them have no default values', array('/foo/{bar}/{foobar}', array('bar' => 'bar')), - '/foo', '#^/foo/(?[^/]+?)/(?[^/]+?)$#s', array('bar', 'foobar'), array( - array('variable', '/', '[^/]+?', 'foobar'), - array('variable', '/', '[^/]+?', 'bar'), + '/foo', '#^/foo/(?[^/]+)/(?[^/]+)$#s', array('bar', 'foobar'), array( + array('variable', '/', '[^/]+', 'foobar'), + array('variable', '/', '[^/]+', 'bar'), array('text', '/foo'), )), array( 'Route with an optional variable as the first segment', array('/{bar}', array('bar' => 'bar')), - '', '#^/(?[^/]+?)?$#s', array('bar'), array( - array('variable', '/', '[^/]+?', 'bar'), + '', '#^/(?[^/]+)?$#s', array('bar'), array( + array('variable', '/', '[^/]+', 'bar'), )), array( @@ -100,8 +100,8 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase array( 'Route with a variable in last position', array('/foo-{bar}'), - '/foo', '#^/foo\-(?[^\-]+?)$#s', array('bar'), array( - array('variable', '-', '[^\-]+?', 'bar'), + '/foo', '#^/foo\-(?[^\-]+)$#s', array('bar'), array( + array('variable', '-', '[^\-]+', 'bar'), array('text', '/foo'), )),