Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions lib/Horde/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,22 @@ 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 ($this->anchor) {
$url .= '#' . ($raw ? $this->anchor : rawurlencode($this->anchor));
}

return strval($url);
return $url;
}

/**
Expand All @@ -297,7 +305,7 @@ public function __toString()
*/
public function link(array $attributes = array())
{
$url = (string)$this->setRaw(false);
$url = strval($this->setRaw(false));
$link = '<a';
if (!empty($url)) {
$link .= " href=\"$url\"";
Expand Down
23 changes: 23 additions & 0 deletions test/Horde/Url/AddHordeUrlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* @author Dmitry Petrov <[email protected]>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @category Horde
* @package Url
* @subpackage UnitTests
*/

namespace Horde\Url;
use \PHPUnit\Framework\TestCase;
use \Horde_Url;

class AddHordeUrlTest extends TestCase
{
public function testAddHordeUrlToExistingUrl()
{
$url = new Horde_Url('test?foo=1&bar=2');
$url->add('url', new Horde_Url('https://example.com/test?_t=123456&_h=Abcd123'));
$this->assertEquals('test?foo=1&bar=2&url=https%3A%2F%2Fexample.com%2Ftest%3F_t%3D123456%26_h%3DAbcd123', (string)$url);
}

}