diff options
author | Andreas Gohr <andi@splitbrain.org> | 2025-01-09 09:55:40 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2025-01-09 09:55:40 +0100 |
commit | 6cc6a0d2d8cfd4379f05b92c2dd838275d7f1edd (patch) | |
tree | c1e88815c9bea3acea8e7ca16641667220eaebf3 | |
parent | dbc152da9efbf46cb3446112ea99f29371e9281a (diff) | |
download | dokuwiki-6cc6a0d2d8cfd4379f05b92c2dd838275d7f1edd.tar.gz dokuwiki-6cc6a0d2d8cfd4379f05b92c2dd838275d7f1edd.zip |
use http_build_query() in buildURLparams()
buildURLparams() is used all throughout the code, but its implementation
was overly simplistic. This changes it to use the much better builtin
http_build_query() function. This allows for correct encoding of array
values or deeper nested structures.
-rw-r--r-- | inc/common.php | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/inc/common.php b/inc/common.php index f0aa5b31f..dba3500ca 100644 --- a/inc/common.php +++ b/inc/common.php @@ -346,24 +346,15 @@ function mediainfo() /** * Build an string of URL parameters * - * @param array $params array with key-value pairs + * @see http_build_query() + * @param array|object $params the data to encode * @param string $sep series of pairs are separated by this character * @return string query string - * @author Andreas Gohr * */ function buildURLparams($params, $sep = '&') { - $url = ''; - $amp = false; - foreach ($params as $key => $val) { - if ($amp) $url .= $sep; - - $url .= rawurlencode($key) . '='; - $url .= rawurlencode((string)$val); - $amp = true; - } - return $url; + return http_build_query($params, '', $sep, PHP_QUERY_RFC3986); } /** |