Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit5d12f0c

Browse files
fixed absolute url generation for query strings
1 parentda35163 commit5d12f0c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

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

73+
if ('#' ===$path[0]) {
74+
$queryString =$this->requestContext->getQueryString();
75+
$path =$this->requestContext->getPathInfo().($queryString ?'?'.$queryString :'').$path;
76+
}
77+
78+
if ('?' ===$path[0]) {
79+
$path =$this->requestContext->getPathInfo().$path;
80+
}
81+
7382
if ('/' !==$path[0]) {
7483
$path =rtrim($this->requestContext->getBaseUrl(),'/').'/'.$path;
7584
}
@@ -80,6 +89,14 @@ public function generateAbsoluteUrl($path)
8089
return$path;
8190
}
8291

92+
if ('#' ===$path[0]) {
93+
$path =$request->getRequestUri().$path;
94+
}
95+
96+
if ('?' ===$path[0]) {
97+
$path =$request->getPathInfo().$path;
98+
}
99+
83100
if (!$path ||'/' !==$path[0]) {
84101
$prefix =$request->getPathInfo();
85102
$last =strlen($prefix) -1;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ 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('http://localhost/foo/bar?baz','?baz','/foo/bar'),
47+
array('http://localhost/foo/bar?baz=1','?baz=1','/foo/bar?foo=1'),
48+
array('http://localhost/foo/baz?baz=1','baz?baz=1','/foo/bar?foo=1'),
49+
50+
array('http://localhost/foo/bar#baz','#baz','/foo/bar'),
51+
array('http://localhost/foo/bar?baz=1#baz','?baz=1#baz','/foo/bar?foo=1'),
52+
array('http://localhost/foo/baz?baz=1#baz','baz?baz=1#baz','/foo/bar?foo=1'),
4553
);
4654
}
4755

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp