Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 27 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -21,8 +21,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.4-dev",
"dev-develop": "2.5-dev"
"dev-master": "2.1-dev",
"dev-develop": "2.2-dev"
}
},
"autoload-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Expand Up @@ -1334,7 +1334,7 @@ protected function doRequest(Http $uri, $method, $secure = false, $headers = arr
* @param string $password
* @param string $type
* @return string
* @throws Zend\Http\Client\Exception\InvalidArgumentException
* @throws Client\Exception\InvalidArgumentException
*/
public static function encodeAuthHeader($user, $password, $type = self::AUTH_BASIC)
{
Expand Down
7 changes: 3 additions & 4 deletions src/Client/Adapter/Test.php
Expand Up @@ -98,10 +98,9 @@ public function setOptions($options = array())
/**
* Connect to the remote server
*
* @param string $host
* @param int $port
* @param bool $secure
* @param int $timeout
* @param string $host
* @param int $port
* @param bool $secure
* @throws Exception\RuntimeException
*/
public function connect($host, $port = 80, $secure = false)
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Cookies.php
Expand Up @@ -328,7 +328,7 @@ protected function _matchPath($domains, $path)
* of the cookie.
*
* @param Response $response HTTP Response object
* @param Uri\Uri|string $uri The requested URI
* @param Uri\Uri|string $refUri The requested URI
* @return Cookies
* @todo Add the $uri functionality.
*/
Expand Down
17 changes: 12 additions & 5 deletions src/Header/AbstractAccept.php
Expand Up @@ -168,7 +168,7 @@ protected function getParametersFromFieldValuePart($fieldValuePart)
$explode = explode('=', $param, 2);

$value = trim($explode[1]);
if ($value[0] == '"' && substr($value, -1) == '"') {
if (isset($value[0]) && $value[0] == '"' && substr($value, -1) == '"') {
$value = substr(substr($value, 1), 0, -1);
}

Expand Down Expand Up @@ -341,10 +341,17 @@ protected function matchAcceptParams($match1, $match2)
foreach ($match2->params as $key => $value) {
if (isset($match1->params[$key])) {
if (strpos($value, '-')) {
$values = explode('-', $value, 2);
if ($values[0] > $match1->params[$key] ||
$values[1] < $match1->params[$key])
{
preg_match(
'/^(?|([^"-]*)|"([^"]*)")-(?|([^"-]*)|"([^"]*)")\z/',
$value,
$pieces
);

if (count($pieces) == 3 &&
(version_compare($pieces[1], $match1->params[$key], '<=') xor
version_compare($pieces[2], $match1->params[$key], '>=')
)
) {
return false;
}
} elseif (strpos($value, '|')) {
Expand Down
Expand Up @@ -42,7 +42,7 @@ public function __construct($internalValues)
/**
* Set a Field Value Part this Field Value Part matched against.
*
* @param AbstractFieldValuePart $matchedPart
* @param AbstractFieldValuePart $matchedAgainst
* @return AbstractFieldValuePart provides fluent interface
*/
public function setMatchedAgainst(AbstractFieldValuePart $matchedAgainst)
Expand Down
5 changes: 3 additions & 2 deletions src/Header/SetCookie.php
Expand Up @@ -132,7 +132,8 @@ public static function fromString($headerLine, $bypassHeaderFieldName = false)
};
}

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = explode(':', $headerLine, 2);
$value = ltrim($value);

// some sites return set-cookie::value, this is to get rid of the second :
$name = (strtolower($name) =='set-cookie:') ? 'set-cookie' : $name;
Expand Down Expand Up @@ -227,7 +228,7 @@ public function getFieldName()
public function getFieldValue()
{
if ($this->getName() == '') {
throw new Exception\RuntimeException('A cookie name is required to generate a field value for this cookie');
return '';
}

$value = $this->getValue();
Expand Down
2 changes: 1 addition & 1 deletion src/Headers.php
Expand Up @@ -25,7 +25,7 @@
class Headers implements Countable, Iterator
{
/**
* @var \Zend\Loader\PluginClassLoader
* @var PluginClassLoader
*/
protected $pluginClassLoader = null;

Expand Down
2 changes: 1 addition & 1 deletion src/Response.php
Expand Up @@ -508,7 +508,7 @@ protected function decodeDeflate($body)
* Some servers (IIS ?) send a broken deflate response, without the
* RFC-required zlib header.
*
* We try to detect the zlib header, and if it does not exsit we
* We try to detect the zlib header, and if it does not exist we
* teat the body is plain DEFLATE content.
*
* This method was adapted from PEAR HTTP_Request2 by (c) Alexey Borzov
Expand Down
71 changes: 63 additions & 8 deletions test/Header/AcceptTest.php
Expand Up @@ -280,6 +280,59 @@ public function testWildcardWithDifferentParamsAndRanges()
$this->assertEquals('21', $res->getParams()->version);
}

/**
* @group 3739
* @covers Accept::matchAcceptParams()
*/
public function testParamRangesWithDecimals()
{
$acceptHeader = Accept::fromString('Accept: application/vnd.com.example+xml; version=10');
$this->assertFalse($acceptHeader->match('application/vnd.com.example+xml; version="\"3.1\"-\"3.1.1-DEV\""'));
}

/**
* @group 3740
* @dataProvider provideParamRanges
* @covers Accept::matchAcceptParams()
* @covers Accept::getParametersFromFieldValuePart()
*/
public function testParamRangesSupportDevStage($range, $input, $success)
{
$acceptHeader = Accept::fromString(
'Accept: application/vnd.com.example+xml; version="' . addslashes($input) . '"'
);

$res = $acceptHeader->match(
'application/vnd.com.example+xml; version="' . addslashes($range) . '"'
);

if ($success) {
$this->assertInstanceOf('Zend\Http\Header\Accept\FieldValuePart\AcceptFieldValuePart', $res);
} else {
$this->assertFalse($res);
}
}

/**
* @group 3740
* @return array
*/
public function provideParamRanges()
{
return array(
array('"3.1.1-DEV"-3.1.1', '3.1.1', true),
array('3.1.0-"3.1.1-DEV"', '3.1.1', false),
array('3.1.0-"3.1.1-DEV"', '3.1.1-DEV', true),
array('3.1.0-"3.1.1-DEV"', '3.1.2-DEV', false),
array('3.1.0-"3.1.1"', '3.1.2-DEV', false),
array('3.1.0-"3.1.1"', '3.1.0-DEV', false),
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.0', true),
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.1', false),
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.1-BETA', true),
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.0-DEV', true),
);
}

public function testVersioningAndPriorization()
{
$acceptStr = 'Accept: text/html; version=23, text/json; version=15.3; q=0.9,' .
Expand All @@ -301,14 +354,16 @@ public function testVersioningAndPriorization()
$this->assertEquals($value, $res->$key);
}

$expected = (object) array('typeString' => 'text/html',
'type' => 'text',
'subtype' => 'html',
'subtypeRaw' => 'html',
'format' => 'html',
'priority' => 0.4,
'params' => array('q' => 0.4, 'level' => 2),
'raw' => 'text/html;level=2;q=0.4');
$expected = (object) array(
'typeString' => 'text/html',
'type' => 'text',
'subtype' => 'html',
'subtypeRaw' => 'html',
'format' => 'html',
'priority' => 0.4,
'params' => array('q' => 0.4, 'level' => 2),
'raw' => 'text/html;level=2;q=0.4'
);

$str = 'text/html; version=17,text/json; version=15-16; q=0.5';
$res = $acceptHeader->match($str);
Expand Down
11 changes: 10 additions & 1 deletion test/Header/SetCookieTest.php
Expand Up @@ -334,7 +334,16 @@ public static function validCookieWithInfoProvider()
),
'myname=myvalue; Expires=Wed, 13-Jan-2021 22:23:01 GMT; Domain=docs.foo.com; Path=/accounts; Secure; HttpOnly'
),
array(
'Set-Cookie:',
array(),
''
),
array(
'Set-Cookie: ',
array(),
''
),
);
}

}

0 comments on commit 42763a8

Please sign in to comment.