@@ -110,8 +110,8 @@ public function provideCompileData()
110110 array (
111111 'Route with an optional variable as the first segment with requirements ' ,
112112 array ('/{bar} ' , array ('bar ' => 'bar ' ), array ('bar ' => '(foo|bar) ' )),
113- '' , '#^/(?P<bar>(foo|bar))?$#sD ' , array ('bar ' ), array (
114- array ('variable ' , '/ ' , '(foo|bar) ' , 'bar ' ),
113+ '' , '#^/(?P<bar>(?: foo|bar))?$#sD ' , array ('bar ' ), array (
114+ array ('variable ' , '/ ' , '(?: foo|bar) ' , 'bar ' ),
115115 ),
116116 ),
117117
@@ -146,10 +146,10 @@ public function provideCompileData()
146146 array (
147147 'Route without separator between variables ' ,
148148 array ('/{w}{x}{y}{z}.{_format} ' , array ('z ' => 'default-z ' , '_format ' => 'html ' ), array ('y ' => '(y|Y) ' )),
149- '' , '#^/(?P<w>[^/\.]+)(?P<x>[^/\.]+)(?P<y>(y|Y))(?:(?P<z>[^/\.]++)(?:\.(?P<_format>[^/]++))?)?$#sD ' , array ('w ' , 'x ' , 'y ' , 'z ' , '_format ' ), array (
149+ '' , '#^/(?P<w>[^/\.]+)(?P<x>[^/\.]+)(?P<y>(?: y|Y))(?:(?P<z>[^/\.]++)(?:\.(?P<_format>[^/]++))?)?$#sD ' , array ('w ' , 'x ' , 'y ' , 'z ' , '_format ' ), array (
150150 array ('variable ' , '. ' , '[^/]++ ' , '_format ' ),
151151 array ('variable ' , '' , '[^/\.]++ ' , 'z ' ),
152- array ('variable ' , '' , '(y|Y) ' , 'y ' ),
152+ array ('variable ' , '' , '(?: y|Y) ' , 'y ' ),
153153 array ('variable ' , '' , '[^/\.]+ ' , 'x ' ),
154154 array ('variable ' , '/ ' , '[^/\.]+ ' , 'w ' ),
155155 ),
@@ -380,6 +380,25 @@ public function testRouteWithTooLongVariableName()
380380 $ route = new Route (sprintf ('/{%s} ' , str_repeat ('a ' , RouteCompiler::VARIABLE_MAXIMUM_LENGTH + 1 )));
381381 $ route ->compile ();
382382 }
383+
384+ /**
385+ * @dataProvider provideRemoveCapturingGroup
386+ */
387+ public function testRemoveCapturingGroup ($ regex , $ requirement )
388+ {
389+ $ route = new Route ('/{foo} ' , array (), array ('foo ' => $ requirement ));
390+
391+ $ this ->assertSame ($ regex , $ route ->compile ()->getRegex ());
392+ }
393+
394+ public function provideRemoveCapturingGroup ()
395+ {
396+ yield array ('#^/(?P<foo>a(?:b|c)(?:d|e)f)$#sD ' , 'a(b|c)(d|e)f ' );
397+ yield array ('#^/(?P<foo>a\(b\)c)$#sD ' , 'a\(b\)c ' );
398+ yield array ('#^/(?P<foo>(?:b))$#sD ' , '(?:b) ' );
399+ yield array ('#^/(?P<foo>(?(b)b))$#sD ' , '(?(b)b) ' );
400+ yield array ('#^/(?P<foo>(*F))$#sD ' , '(*F) ' );
401+ }
383402}
384403
385404class Utf8RouteCompiler extends RouteCompiler
0 commit comments