Skip to content

Commit 564b5cb

Browse files
authored
Merge pull request dokuwiki#4389 from dokuwiki/buildquery
use http_build_query() in buildURLparams()
2 parents 99acb4b + 058c6ba commit 564b5cb

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

_test/tests/inc/parser/parser_media.test.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function testVideoOGVExternal() {
3131
$source = '<source src="http://some.where.far/away.ogv" type="video/ogg" />';
3232
$this->assertEquals(substr($url,67,64),$source);
3333
// work around random token
34-
$a_first_part = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?cache=&amp;tok=';
34+
$a_first_part = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?tok=';
3535
$a_second_part = '&amp;media=http%3A%2F%2Fsome.where.far%2Faway.ogv" class="media mediafile mf_ogv" title="http://some.where.far/away.ogv">';
3636

3737
$substr_start = 132;
@@ -119,12 +119,12 @@ function testVideoOGVInternal() {
119119
$this->assertNotSame(false, $substr_start, 'Substring not found.');
120120

121121
// find $a_webm in $url
122-
$a_webm = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?id=&amp;cache=&amp;media=wiki:kind_zu_katze.webm" class="media mediafile mf_webm" title="wiki:kind_zu_katze.webm (99.1'."\xC2\xA0".'KB)">kind_zu_katze.webm</a>';
122+
$a_webm = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.webm" class="media mediafile mf_webm" title="wiki:kind_zu_katze.webm (99.1'."\xC2\xA0".'KB)">kind_zu_katze.webm</a>';
123123
$substr_start = strpos($url, $a_webm, $substr_start + strlen($source_ogv));
124124
$this->assertNotSame(false, $substr_start, 'Substring not found.');
125125

126126
// find $a_webm in $url
127-
$a_ogv = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?id=&amp;cache=&amp;media=wiki:kind_zu_katze.ogv" class="media mediafile mf_ogv" title="wiki:kind_zu_katze.ogv (44.8'."\xC2\xA0".'KB)">kind_zu_katze.ogv</a>';
127+
$a_ogv = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.ogv" class="media mediafile mf_ogv" title="wiki:kind_zu_katze.ogv (44.8'."\xC2\xA0".'KB)">kind_zu_katze.ogv</a>';
128128
$substr_start = strpos($url, $a_ogv, $substr_start + strlen($a_webm));
129129
$this->assertNotSame(false, $substr_start, 'Substring not found.');
130130

inc/common.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -347,24 +347,15 @@ function mediainfo()
347347
/**
348348
* Build an string of URL parameters
349349
*
350-
* @param array $params array with key-value pairs
350+
* @see http_build_query()
351+
* @param array|object $params the data to encode
351352
* @param string $sep series of pairs are separated by this character
352353
* @return string query string
353-
* @author Andreas Gohr
354354
*
355355
*/
356356
function buildURLparams($params, $sep = '&amp;')
357357
{
358-
$url = '';
359-
$amp = false;
360-
foreach ($params as $key => $val) {
361-
if ($amp) $url .= $sep;
362-
363-
$url .= rawurlencode($key) . '=';
364-
$url .= rawurlencode((string)$val);
365-
$amp = true;
366-
}
367-
return $url;
358+
return http_build_query($params, '', $sep, PHP_QUERY_RFC3986);
368359
}
369360

370361
/**

0 commit comments

Comments
 (0)