1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-25 02:22:57 +01:00

Allows for 0 integers to be added as URL paths

This commit is contained in:
Jamie Hannaford 2014-01-29 16:47:38 +01:00
parent cf95dff4da
commit 17b483600d
2 changed files with 8 additions and 2 deletions

View File

@ -314,13 +314,13 @@ class Url
/**
* Add a relative path to the currently set path
*
* @param string $relativePath Relative path to add
* @param string|int $relativePath Relative path to add
*
* @return Url
*/
public function addPath($relativePath)
{
if (!$relativePath || $relativePath == '/') {
if ((!is_string($relativePath) && !is_int($relativePath)) || strlen($relativePath) === 0 || $relativePath === '/') {
return $this;
}

View File

@ -127,11 +127,17 @@ class UrlTest extends \Guzzle\Tests\GuzzleTestCase
{
// Does nothing here
$this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath(false));
$this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath(null));
$this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath(array()));
$this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath(new \stdClass()));
$this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath(''));
$this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath('/'));
$this->assertEquals('http://e.com/base/relative?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath('relative'));
$this->assertEquals('http://e.com/base/relative?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath('/relative'));
$this->assertEquals('http://e.com/base/0', (string) Url::factory('http://e.com/base')->addPath(0));
$this->assertEquals('http://e.com/base/0/1', (string) Url::factory('http://e.com/base')->addPath('0')->addPath('1'));
}
/**