mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: HTTP::setGetVar() returns a relative URL if a relative URL is passed, to make behaviour closer to 2.3
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@101392 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
5804a20a18
commit
5dfadd0e9c
@ -94,8 +94,12 @@ class HTTP {
|
||||
public static function setGetVar($varname, $varvalue, $currentURL = null) {
|
||||
$uri = $currentURL ? $currentURL : Director::makeRelative($_SERVER['REQUEST_URI']);
|
||||
|
||||
$isRelative = false;
|
||||
// We need absolute URLs for parse_url()
|
||||
if(Director::is_relative_url($uri)) $uri = Director::absoluteBaseURL() . $uri;
|
||||
if(Director::is_relative_url($uri)) {
|
||||
$uri = Director::absoluteBaseURL() . $uri;
|
||||
$isRelative = true;
|
||||
}
|
||||
|
||||
// try to parse uri
|
||||
$parts = parse_url($uri);
|
||||
@ -129,7 +133,8 @@ class HTTP {
|
||||
: ''
|
||||
);
|
||||
|
||||
return $newUri;
|
||||
if($isRelative) return Director::makeRelative($newUri);
|
||||
else return $newUri;
|
||||
}
|
||||
|
||||
static function RAW_setGetVar($varname, $varvalue, $currentURL = null) {
|
||||
|
@ -53,9 +53,7 @@ class HTTPTest extends SapphireTest {
|
||||
|
||||
// TODO This should test the absolute URL, but we can't get it reliably
|
||||
// with port and auth URI parts.
|
||||
$expectedBasePath = Director::baseURL();
|
||||
|
||||
foreach(array($expectedPath, 'foo=bar') as $e) {
|
||||
foreach(array(Director::makeRelative($expectedPath), 'foo=bar') as $e) {
|
||||
$this->assertContains(
|
||||
$e,
|
||||
HTTP::setGetVar('foo', 'bar'),
|
||||
@ -63,21 +61,16 @@ class HTTPTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
foreach(array($expectedBasePath, '/relative/url?foo=bar') as $e) {
|
||||
$this->assertContains(
|
||||
$e,
|
||||
HTTP::setGetVar('foo', 'bar', 'relative/url'),
|
||||
'Relative URL without slash prefix returns URL with absolute base'
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
'relative/url?foo=bar',
|
||||
HTTP::setGetVar('foo', 'bar', 'relative/url'),
|
||||
'Relative URL without existing query params');
|
||||
|
||||
foreach(array($expectedBasePath, '/relative/url?baz=buz&foo=bar') as $e) {
|
||||
$this->assertContains(
|
||||
$e,
|
||||
HTTP::setGetVar('foo', 'bar', '/relative/url?baz=buz'),
|
||||
'Relative URL with existing query params, and new added key'
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
'relative/url?baz=buz&foo=bar',
|
||||
HTTP::setGetVar('foo', 'bar', '/relative/url?baz=buz'),
|
||||
'Relative URL with existing query params, and new added key'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'http://test.com/?foo=new&buz=baz',
|
||||
|
Loading…
Reference in New Issue
Block a user