Skip to content

Commit

Permalink
MDL-29161 weblib: moodle_ulr::out does not cope with array params.
Browse files Browse the repository at this point in the history
Conflicts:

	lib/simpletest/testweblib.php
  • Loading branch information
timhunt committed Feb 23, 2012
1 parent 62b0af5 commit 0f75136
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lib/simpletest/testweblib.php
Expand Up @@ -105,6 +105,25 @@ function test_fix_non_standard_entities() {
$this->assertEqual(fix_non_standard_entities('£ä'), '£ä');
}

function test_moodle_url_round_trip() {
$strurl = 'http://moodle.org/course/view.php?id=5';
$url = new moodle_url($strurl);
$this->assertEqual($strurl, $url->out(false));

$strurl = 'http://moodle.org/user/index.php?contextid=53&sifirst=M&silast=D';
$url = new moodle_url($strurl);
$this->assertEqual($strurl, $url->out(false));
}

function test_moodle_url_round_trip_array_params() {
$strurl = 'http://example.com/?a%5B1%5D=1&a%5B2%5D=2';
$url = new moodle_url($strurl);
$this->assertEqual($strurl, $url->out(false));

$url = new moodle_url('http://example.com/?a[1]=1&a[2]=2');
$this->assertEqual($strurl, $url->out(false));
}

function test_compare_url() {
$url1 = new moodle_url('index.php', array('var1' => 1, 'var2' => 2));
$url2 = new moodle_url('index2.php', array('var1' => 1, 'var2' => 2, 'var3' => 3));
Expand Down
8 changes: 7 additions & 1 deletion lib/weblib.php
Expand Up @@ -494,7 +494,13 @@ public function get_query_string($escaped = true, array $overrideparams = null)
$params = $this->params;
}
foreach ($params as $key => $val) {
$arr[] = rawurlencode($key)."=".rawurlencode($val);
if (is_array($val)) {
foreach ($val as $index => $value) {
$arr[] = rawurlencode($key.'['.$index.']')."=".rawurlencode($value);
}
} else {
$arr[] = rawurlencode($key)."=".rawurlencode($val);
}
}
if ($escaped) {
return implode('&', $arr);
Expand Down

0 comments on commit 0f75136

Please sign in to comment.