1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-24 18:13:00 +01:00

Fixing dot segment removal, how absolute URLs are detected, the namespace used for functions.php, and how segments of a path are returned

This commit is contained in:
Michael Dowling 2014-02-21 11:47:05 -08:00
parent 39d56dfffc
commit 7fcf225d0e
5 changed files with 17 additions and 5 deletions

View File

@ -217,11 +217,11 @@ class Client implements ClientInterface
private function buildUrl($url)
{
if (!is_array($url)) {
if (substr($url, 0, 4) === 'http') {
if (strpos($url, '://')) {
return (string) $url;
}
return (string) $this->baseUrl->combine($url);
} elseif (substr($url[0], 0, 4) == 'http') {
} elseif (strpos($url[0], '://')) {
return \GuzzleHttp\uriTemplate($url[0], $url[1]);
}

View File

@ -374,7 +374,7 @@ class Url
*/
public function getPathSegments()
{
return array_slice(explode('/', $this->getPath()), 1);
return explode('/', $this->path);
}
/**

View File

@ -3,7 +3,7 @@
namespace GuzzleHttp;
use GuzzleHttp\Message\ResponseInterface;
use GuzzleHttp\Url\UriTemplate;
use GuzzleHttp\UriTemplate;
const VERSION = '4.0-dev';
@ -122,6 +122,8 @@ function options($url, array $options = [])
*
* @param string $template URI template
* @param array $variables Template variables
*
* @return string
*/
function uriTemplate($template, array $variables)
{

View File

@ -243,6 +243,15 @@ class ClientTest extends \PHPUnit_Framework_TestCase
);
}
public function testCanSetRelativeUrlStartingWithHttp()
{
$client = new Client(['base_url' => 'http://www.foo.com']);
$this->assertEquals(
'http://www.foo.com/httpfoo',
$client->createRequest('GET', 'httpfoo')->getUrl()
);
}
public function testClientSendsRequests()
{
$response = new Response(200);

View File

@ -110,7 +110,7 @@ class UrlTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('test', $url->getPath());
$url->setPath('/test/123/abc');
$this->assertEquals(array('test', '123', 'abc'), $url->getPathSegments());
$this->assertEquals(array('', 'test', '123', 'abc'), $url->getPathSegments());
$parts = parse_url('http://www.test.com/test');
$parts['path'] = '';
@ -260,6 +260,7 @@ class UrlTest extends \PHPUnit_Framework_TestCase
array('/b/c/./../../g', '/g'),
array('/c/./../../g', '/g'),
array('/./../../g', '/g'),
array('foo', 'foo'),
);
}