-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Fixed absolute url generation for query strings and hash urls #23261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,15 @@ public function generateAbsoluteUrl($path) | |
$port = ':'.$this->requestContext->getHttpsPort(); | ||
} | ||
|
||
if ('#' === $path[0]) { | ||
$queryString = $this->requestContext->getQueryString(); | ||
$path = $this->requestContext->getPathInfo().($queryString ? '?'.$queryString : '').$path; | ||
} | ||
|
||
if ('?' === $path[0]) { | ||
$path = $this->requestContext->getPathInfo().$path; | ||
} | ||
|
||
if ('/' !== $path[0]) { | ||
$path = rtrim($this->requestContext->getBaseUrl(), '/').'/'.$path; | ||
} | ||
|
@@ -80,6 +89,14 @@ public function generateAbsoluteUrl($path) | |
return $path; | ||
} | ||
|
||
if ('#' === $path[0]) { | ||
$path = $request->getRequestUri().$path; | ||
} | ||
|
||
if ('?' === $path[0]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also |
||
$path = $request->getPathInfo().$path; | ||
} | ||
|
||
if (!$path || '/' !== $path[0]) { | ||
$prefix = $request->getPathInfo(); | ||
$last = strlen($prefix) - 1; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,14 @@ public function getGenerateAbsoluteUrlData() | |
array('http://example.com/baz', 'http://example.com/baz', '/'), | ||
array('https://example.com/baz', 'https://example.com/baz', '/'), | ||
array('//example.com/baz', '//example.com/baz', '/'), | ||
|
||
array('http://localhost/foo/bar?baz', '?baz', '/foo/bar'), | ||
array('http://localhost/foo/bar?baz=1', '?baz=1', '/foo/bar?foo=1'), | ||
array('http://localhost/foo/baz?baz=1', 'baz?baz=1', '/foo/bar?foo=1'), | ||
|
||
array('http://localhost/foo/bar#baz', '#baz', '/foo/bar'), | ||
array('http://localhost/foo/bar?baz=1#baz', '?baz=1#baz', '/foo/bar?foo=1'), | ||
array('http://localhost/foo/baz?baz=1#baz', 'baz?baz=1#baz', '/foo/bar?foo=1'), | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add this test case? array('http://localhost/foo/bar?0#foo', '#foo', '/foo/bar?0'), I think your current solution will strip out the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test added seems not failing as a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. php -r "var_dump((bool)'0');" ==> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dmaicher can you tell me whats wrong with the test as it should fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah this is only executed when no current request is given (CLI) and the request context is used instead 😉 So your changes from L 73-79 are currently not covered by tests. You need to add some more test cases into the |
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use
elseif
here and also below?