File tree 2 files changed +15
-1
lines changed
Filter options
src/Symfony/Component/Security/Http
2 files changed +15
-1
lines changed
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ class HttpUtils
41
41
public function __construct (UrlGeneratorInterface $ urlGenerator = null , $ urlMatcher = null )
42
42
{
43
43
$ this ->urlGenerator = $ urlGenerator ;
44
- if ($ urlMatcher !== null && !$ urlMatcher instanceof UrlMatcherInterface && !$ urlMatcher instanceof RequestMatcherInterface) {
44
+ if (null !== $ urlMatcher && !$ urlMatcher instanceof UrlMatcherInterface && !$ urlMatcher instanceof RequestMatcherInterface) {
45
45
throw new \InvalidArgumentException ('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface. ' );
46
46
}
47
47
$ this ->urlMatcher = $ urlMatcher ;
@@ -150,7 +150,12 @@ public function generateUri($request, $path)
150
150
// fortunately, they all are, so we have to remove entire query string
151
151
$ position = strpos ($ url , '? ' );
152
152
if (false !== $ position ) {
153
+ $ fragment = parse_url ($ url , PHP_URL_FRAGMENT );
153
154
$ url = substr ($ url , 0 , $ position );
155
+ // fragment must be preserved
156
+ if ($ fragment ) {
157
+ $ url .= "# $ fragment " ;
158
+ }
154
159
}
155
160
156
161
return $ url ;
Original file line number Diff line number Diff line change @@ -252,6 +252,15 @@ public function testGenerateUriRemovesQueryString()
252
252
$ this ->assertEquals ('/foo/bar ' , $ utils ->generateUri (new Request (), 'route_name ' ));
253
253
}
254
254
255
+ public function testGenerateUriPreservesFragment ()
256
+ {
257
+ $ utils = new HttpUtils ($ this ->getUrlGenerator ('/foo/bar?param=value#fragment ' ));
258
+ $ this ->assertEquals ('/foo/bar#fragment ' , $ utils ->generateUri (new Request (), 'route_name ' ));
259
+
260
+ $ utils = new HttpUtils ($ this ->getUrlGenerator ('/foo/bar#fragment ' ));
261
+ $ this ->assertEquals ('/foo/bar#fragment ' , $ utils ->generateUri (new Request (), 'route_name ' ));
262
+ }
263
+
255
264
/**
256
265
* @expectedException \LogicException
257
266
* @expectedExceptionMessage You must provide a UrlGeneratorInterface instance to be able to use routes.
You can’t perform that action at this time.
0 commit comments