Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions lib/Horde/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,10 @@ public function toString($raw = false, $full = true)
}
}

if ($params = $this->parameters) {
foreach ($params as $p => &$v) {
// TODO: Investigate if it should be done for all (or some) other objects
if ($v instanceof Horde_Url) {
$v = strval($v);
}
}
unset($v);

$url .= '?' . http_build_query($params, "", $raw ? '&' : '&');
if ($source = $this->parameters) {
$params = [];
self::encodeParameters($source, '', $params);
$url .= '?' . implode($raw ? '&' : '&', $params);
}

if ($this->anchor) {
Expand All @@ -283,6 +277,38 @@ public function toString($raw = false, $full = true)
return $url;
}

protected static function encodeParameters($source, $prefix, &$params)
{
$index = 0;

foreach ($source as $p => $v) {
if (strlen($prefix)) {
if ($index >= 0 && $p !== $index) {
$index = -1;
}
if ($index >= 0) {
$p = '';
++$index;
} else {
$p = rawurlencode($p);
}
$p = $prefix . '[' . $p . ']';
} else {
$p = rawurlencode($p);
}

if (is_array($v)) {
self::encodeParameters($v, $p, $params);
} else {
$v = (string) $v;
if (strlen($v)) {
$p .= '=' . rawurlencode($v);
}
$params[] = $p;
}
}
}

/**
* Creates the full URL string.
*
Expand Down
Loading