Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5818ebf

Browse filesBrowse files
committed
Preserve URI fragment in HttpUtils::generateUri()
1 parent 0256e59 commit 5818ebf
Copy full SHA for 5818ebf

File tree

2 files changed

+16
-1
lines changed
Filter options

2 files changed

+16
-1
lines changed

‎src/Symfony/Component/Security/Http/HttpUtils.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/HttpUtils.php
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class HttpUtils
4141
public function __construct(UrlGeneratorInterface $urlGenerator = null, $urlMatcher = null)
4242
{
4343
$this->urlGenerator = $urlGenerator;
44-
if ($urlMatcher !== null && !$urlMatcher instanceof UrlMatcherInterface && !$urlMatcher instanceof RequestMatcherInterface) {
44+
if (null !== $urlMatcher && !$urlMatcher instanceof UrlMatcherInterface && !$urlMatcher instanceof RequestMatcherInterface) {
4545
throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
4646
}
4747
$this->urlMatcher = $urlMatcher;
@@ -150,7 +150,16 @@ public function generateUri($request, $path)
150150
// fortunately, they all are, so we have to remove entire query string
151151
$position = strpos($url, '?');
152152
if (false !== $position) {
153+
$fragment = '';
154+
if (false !== $fragmentPosition = strpos($url, '#')) {
155+
$fragment = substr($url, $fragmentPosition + 1);
156+
}
157+
153158
$url = substr($url, 0, $position);
159+
160+
if ('' !== $fragment) {
161+
$url .= "#$fragment";
162+
}
154163
}
155164

156165
return $url;

‎src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ public function testGenerateUriRemovesQueryString()
252252
$this->assertEquals('/foo/bar', $utils->generateUri(new Request(), 'route_name'));
253253
}
254254

255+
public function testGenerateUriPreservesFragmentWhileRemovingQueryString()
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+
255261
/**
256262
* @expectedException \LogicException
257263
* @expectedExceptionMessage You must provide a UrlGeneratorInterface instance to be able to use routes.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.