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) {
|
public static function setGetVar($varname, $varvalue, $currentURL = null) {
|
||||||
$uri = $currentURL ? $currentURL : Director::makeRelative($_SERVER['REQUEST_URI']);
|
$uri = $currentURL ? $currentURL : Director::makeRelative($_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
|
$isRelative = false;
|
||||||
// We need absolute URLs for parse_url()
|
// 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
|
// try to parse uri
|
||||||
$parts = parse_url($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) {
|
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
|
// TODO This should test the absolute URL, but we can't get it reliably
|
||||||
// with port and auth URI parts.
|
// with port and auth URI parts.
|
||||||
$expectedBasePath = Director::baseURL();
|
foreach(array(Director::makeRelative($expectedPath), 'foo=bar') as $e) {
|
||||||
|
|
||||||
foreach(array($expectedPath, 'foo=bar') as $e) {
|
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
$e,
|
$e,
|
||||||
HTTP::setGetVar('foo', 'bar'),
|
HTTP::setGetVar('foo', 'bar'),
|
||||||
@ -63,21 +61,16 @@ class HTTPTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(array($expectedBasePath, '/relative/url?foo=bar') as $e) {
|
$this->assertEquals(
|
||||||
$this->assertContains(
|
'relative/url?foo=bar',
|
||||||
$e,
|
HTTP::setGetVar('foo', 'bar', 'relative/url'),
|
||||||
HTTP::setGetVar('foo', 'bar', 'relative/url'),
|
'Relative URL without existing query params');
|
||||||
'Relative URL without slash prefix returns URL with absolute base'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(array($expectedBasePath, '/relative/url?baz=buz&foo=bar') as $e) {
|
$this->assertEquals(
|
||||||
$this->assertContains(
|
'relative/url?baz=buz&foo=bar',
|
||||||
$e,
|
HTTP::setGetVar('foo', 'bar', '/relative/url?baz=buz'),
|
||||||
HTTP::setGetVar('foo', 'bar', '/relative/url?baz=buz'),
|
'Relative URL with existing query params, and new added key'
|
||||||
'Relative URL with existing query params, and new added key'
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://test.com/?foo=new&buz=baz',
|
'http://test.com/?foo=new&buz=baz',
|
||||||
|
Loading…
Reference in New Issue
Block a user