Fixed absolute url generation for query strings and hash urls
This commit is contained in:
parent
2731787e8b
commit
89ad27d544
@ -70,6 +70,13 @@ class HttpFoundationExtension extends \Twig_Extension
|
|||||||
$port = ':'.$this->requestContext->getHttpsPort();
|
$port = ':'.$this->requestContext->getHttpsPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('#' === $path[0]) {
|
||||||
|
$queryString = $this->requestContext->getQueryString();
|
||||||
|
$path = $this->requestContext->getPathInfo().($queryString ? '?'.$queryString : '').$path;
|
||||||
|
} elseif ('?' === $path[0]) {
|
||||||
|
$path = $this->requestContext->getPathInfo().$path;
|
||||||
|
}
|
||||||
|
|
||||||
if ('/' !== $path[0]) {
|
if ('/' !== $path[0]) {
|
||||||
$path = rtrim($this->requestContext->getBaseUrl(), '/').'/'.$path;
|
$path = rtrim($this->requestContext->getBaseUrl(), '/').'/'.$path;
|
||||||
}
|
}
|
||||||
@ -80,6 +87,12 @@ class HttpFoundationExtension extends \Twig_Extension
|
|||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('#' === $path[0]) {
|
||||||
|
$path = $request->getRequestUri().$path;
|
||||||
|
} elseif ('?' === $path[0]) {
|
||||||
|
$path = $request->getPathInfo().$path;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$path || '/' !== $path[0]) {
|
if (!$path || '/' !== $path[0]) {
|
||||||
$prefix = $request->getPathInfo();
|
$prefix = $request->getPathInfo();
|
||||||
$last = strlen($prefix) - 1;
|
$last = strlen($prefix) - 1;
|
||||||
|
@ -41,6 +41,15 @@ class HttpFoundationExtensionTest extends \PHPUnit_Framework_TestCase
|
|||||||
array('http://example.com/baz', 'http://example.com/baz', '/'),
|
array('http://example.com/baz', 'http://example.com/baz', '/'),
|
||||||
array('https://example.com/baz', 'https://example.com/baz', '/'),
|
array('https://example.com/baz', 'https://example.com/baz', '/'),
|
||||||
array('//example.com/baz', '//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?0#baz', '#baz', '/foo/bar?0'),
|
||||||
|
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'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user