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:
Ingo Schommer 2010-03-11 06:20:46 +00:00 committed by Sam Minnee
parent 7c1f9df776
commit 0f324c852e
2 changed files with 8 additions and 4 deletions

View File

@ -77,6 +77,9 @@ class HTTP {
* Will try to include a GET parameter for an existing URL,
* preserving existing parameters and fragments.
* 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,
* it is prepended with Director::absoluteBaseURL().
@ -117,7 +120,8 @@ class HTTP {
: ''
) . (
($params)
? '?' . http_build_query($params)
// XHTML compliant by default
? '?' . http_build_query($params, null, '&')
: ''
) . (
isset($parts['fragment']) && $parts['fragment'] != ''

View File

@ -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(
$e,
HTTP::setGetVar('foo', 'bar', '/relative/url?baz=buz'),
@ -80,7 +80,7 @@ class HTTPTest extends SapphireTest {
}
$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'),
'Absolute URL without path and multipe existing query params, overwriting an existing parameter'
);
@ -93,7 +93,7 @@ class HTTPTest extends SapphireTest {
$this->assertEquals(
// 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'),
'Absolute URL and PHP array query string notation'
);