mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX #3224 ajshort: Get HTTP::setGetVar() working with variables that contain array indexes
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@69700 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
d46cde0ae1
commit
63de49eab1
@ -73,15 +73,12 @@ class HTTP {
|
||||
return $content;
|
||||
}
|
||||
|
||||
static function setGetVar($varname, $varvalue, $currentURL = null) {
|
||||
$currentURL = $currentURL ? $currentURL : $_SERVER['REQUEST_URI'];
|
||||
public static function setGetVar($varname, $varvalue, $currentURL = null) {
|
||||
$scriptbase = $currentURL ? $currentURL : $_SERVER['REQUEST_URI'];
|
||||
|
||||
$scriptbase = $currentURL;
|
||||
$scriptbase = str_replace('&','&',$scriptbase);
|
||||
|
||||
$scriptbase = ereg_replace("&$varname=[^&]*",'',$scriptbase);
|
||||
$scriptbase = ereg_replace("\?$varname=[^&]*&",'?',$scriptbase);
|
||||
$scriptbase = ereg_replace("\?$varname=[^&]*",'',$scriptbase);
|
||||
$scriptbase = str_replace('&', '&', $scriptbase);
|
||||
$scriptbase = preg_replace('/\?' . quotemeta($varname) . '=([^&]*)&/', '?', $scriptbase);
|
||||
$scriptbase = preg_replace('/([\?&]+)' . quotemeta($varname) . '=([^&]*)/', null, $scriptbase);
|
||||
|
||||
$suffix = '';
|
||||
if(($hashPos = strpos($scriptbase,'#')) !== false) {
|
||||
|
29
tests/HTTPTest.php
Normal file
29
tests/HTTPTest.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests the {@link HTTP} class
|
||||
*
|
||||
* @package sapphire
|
||||
* @subpackage tests
|
||||
*/
|
||||
class HTTPTest extends SapphireTest {
|
||||
|
||||
/**
|
||||
* Tests {@link HTTP::setGetVar()}
|
||||
*/
|
||||
public function testSetGetVar() {
|
||||
$expected = array (
|
||||
'/?foo=bar' => array('foo', 'bar', '/'),
|
||||
'/?baz=buz&foo=bar' => array('foo', 'bar', '/?baz=buz'),
|
||||
'/?buz=baz&foo=baz' => array('foo', 'baz', '/?foo=bar&buz=baz'),
|
||||
'/?foo=var' => array('foo', 'var', '/?foo=&foo=bar'),
|
||||
'/?foo[test]=var' => array('foo[test]', 'var', '/?foo[test]=another')
|
||||
);
|
||||
|
||||
foreach($expected as $result => $args) {
|
||||
$this->assertEquals(
|
||||
call_user_func_array(array('HTTP', 'setGetVar'), $args), str_replace('&', '&', $result)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user