8000 fixed absolute url generation for query strings · symfony/symfony@14399e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 14399e5

Browse files
fixed absolute url generation for query strings
1 parent da35163 commit 14399e5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public function generateAbsoluteUrl($path)
7070
$port = ':'.$this->requestContext->getHttpsPort();
7171
}
7272

73+
if ('?' === $path[0]) {
74+
$path = $this->requestContext->getPathInfo() . $path;
75+
}
76+
7377
if ('/' !== $path[0]) {
7478
$path = rtrim($this->requestContext->getBaseUrl(), '/').'/'.$path;
7579
}
@@ -80,6 +84,10 @@ public function generateAbsoluteUrl($path)
8084
return $path;
8185
}
8286

87+
if ('?' === $path[0]) {
88+
$path = $request->getPathInfo() . $path;
89+
}
90+
8391
if (!$path || '/' !== $path[0]) {
8492
$prefix = $request->getPathInfo();
8593
$last = strlen($prefix) - 1;

src/Symfony/Bridge/Twig/Tests/Extension/HttpFoundationExtensionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function getGenerateAbsoluteUrlData()
4242
array('http://example.com/baz', 'http://example.com/baz', '/'),
4343
array('https://example.com/baz', 'https://example.com/baz', '/'),
4444
array('//example.com/baz', '//example.com/baz', '/'),
45+
46+
array('https://example.com/foo/bar?baz', '?baz', '/foo/bar'),
47+
array('https://example.com/foo/bar?baz=1', '?baz=1', '/foo/bar?foo=1'),
48+
array('https://example.com/foo/baz?baz=1', 'baz?baz=1', '/foo/bar?foo=1'),
4549
);
4650
}
4751

0 commit comments

Comments
 (0)
0