mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Produce XHTML compliant URLs in HTTP::setGetVar() by default (regression from r98373, see #5101)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@100904 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
7c1f9df776
commit
0f324c852e
@ -77,6 +77,9 @@ class HTTP {
|
|||||||
* Will try to include a GET parameter for an existing URL,
|
* Will try to include a GET parameter for an existing URL,
|
||||||
* preserving existing parameters and fragments.
|
* preserving existing parameters and fragments.
|
||||||
* If no URL is given, falls back to $_SERVER['REQUEST_URI'].
|
* If no URL is given, falls back to $_SERVER['REQUEST_URI'].
|
||||||
|
* Uses parse_url() to dissect the URL, and http_build_query() to reconstruct it
|
||||||
|
* with the additional parameter. Converts any '&' (ampersand)
|
||||||
|
* URL parameter separators to the more XHTML compliant '&'.
|
||||||
*
|
*
|
||||||
* CAUTION: If the URL is determined to be relative,
|
* CAUTION: If the URL is determined to be relative,
|
||||||
* it is prepended with Director::absoluteBaseURL().
|
* it is prepended with Director::absoluteBaseURL().
|
||||||
@ -117,7 +120,8 @@ class HTTP {
|
|||||||
: ''
|
: ''
|
||||||
) . (
|
) . (
|
||||||
($params)
|
($params)
|
||||||
? '?' . http_build_query($params)
|
// XHTML compliant by default
|
||||||
|
? '?' . http_build_query($params, null, '&')
|
||||||
: ''
|
: ''
|
||||||
) . (
|
) . (
|
||||||
isset($parts['fragment']) && $parts['fragment'] != ''
|
isset($parts['fragment']) && $parts['fragment'] != ''
|
||||||
|
@ -71,7 +71,7 @@ class HTTPTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(array($expectedBasePath, '/relative/url?baz=buz&foo=bar') as $e) {
|
foreach(array($expectedBasePath, '/relative/url?baz=buz&foo=bar') as $e) {
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
$e,
|
$e,
|
||||||
HTTP::setGetVar('foo', 'bar', '/relative/url?baz=buz'),
|
HTTP::setGetVar('foo', 'bar', '/relative/url?baz=buz'),
|
||||||
@ -80,7 +80,7 @@ class HTTPTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://test.com/?foo=new&buz=baz',
|
'http://test.com/?foo=new&buz=baz',
|
||||||
HTTP::setGetVar('foo', 'new', 'http://test.com/?foo=old&buz=baz'),
|
HTTP::setGetVar('foo', 'new', 'http://test.com/?foo=old&buz=baz'),
|
||||||
'Absolute URL without path and multipe existing query params, overwriting an existing parameter'
|
'Absolute URL without path and multipe existing query params, overwriting an existing parameter'
|
||||||
);
|
);
|
||||||
@ -93,7 +93,7 @@ class HTTPTest extends SapphireTest {
|
|||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
// http_build_query() escapes angular brackets, they should be correctly urldecoded by the browser client
|
// http_build_query() escapes angular brackets, they should be correctly urldecoded by the browser client
|
||||||
'http://test.com/?foo%5Btest%5D=one&foo%5Btest%5D=two',
|
'http://test.com/?foo%5Btest%5D=one&foo%5Btest%5D=two',
|
||||||
HTTP::setGetVar('foo[test]', 'two', 'http://test.com/?foo[test]=one'),
|
HTTP::setGetVar('foo[test]', 'two', 'http://test.com/?foo[test]=one'),
|
||||||
'Absolute URL and PHP array query string notation'
|
'Absolute URL and PHP array query string notation'
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user