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

Commit

Permalink
Merge branch 'feature/7263'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Mar 25, 2015
2 parents cea51ea + a552699 commit b44104c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ public function getCookie($uri, $cookieName, $retAs = self::COOKIE_OBJECT)

// Get correct cookie path
$path = $uri->getPath();
$path = substr($path, 0, strrpos($path, '/'));
$lastSlashPos = strrpos($path, '/') ?: 0;
$path = substr($path, 0, $lastSlashPos);
if (! $path) {
$path = '/';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Accept.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function parseFieldValuePart($fieldValuePart)
if ($pos = strpos($fieldValuePart, '/')) {
$type = trim(substr($fieldValuePart, 0, $pos));
} else {
$type = trim(substr($fieldValuePart, 0));
$type = trim($fieldValuePart);
}

$params = $this->getParametersFromFieldValuePart($fieldValuePart);
Expand Down
16 changes: 13 additions & 3 deletions src/Header/CacheControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public static function fromString($headerLine)

// check to ensure proper header type for this factory
if (strtolower($name) !== 'cache-control') {
throw new Exception\InvalidArgumentException('Invalid header line for Cache-Control string: "' . $name . '"');
throw new Exception\InvalidArgumentException(sprintf(
'Invalid header line for Cache-Control string: ""',
$name
));
}

$directives = static::parseValue($value);
Expand Down Expand Up @@ -179,6 +182,7 @@ protected static function parseValue($value)
case 0:
$directive = $lastMatch;
goto state_value;
// intentional fall-through

default:
throw new Exception\InvalidArgumentException('expected DIRECTIVE');
Expand All @@ -189,10 +193,12 @@ protected static function parseValue($value)
case 0:
$directives[$directive] = substr($lastMatch, 2, -1);
goto state_separator;
// intentional fall-through

case 1:
$directives[$directive] = rtrim(substr($lastMatch, 1));
goto state_separator;
// intentional fall-through

default:
$directives[$directive] = true;
Expand All @@ -203,6 +209,7 @@ protected static function parseValue($value)
switch (static::match(array('\s*,\s*', '$'), $value, $lastMatch)) {
case 0:
goto state_directive;
// intentional fall-through

case 1:
return $directives;
Expand All @@ -223,10 +230,13 @@ protected static function parseValue($value)
*/
protected static function match($tokens, &$string, &$lastMatch)
{
// Ensure we have a string
$value = (string) $string;

foreach ($tokens as $i => $token) {
if (preg_match('/^' . $token . '/', $string, $matches)) {
if (preg_match('/^' . $token . '/', $value, $matches)) {
$lastMatch = $matches[0];
$string = substr($string, strlen($matches[0]));
$string = substr($value, strlen($matches[0]));
return $i;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/PhpEnvironment/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ public function setServer(ParametersInterface $server)

// URI scheme
if ((!empty($this->serverParams['HTTPS']) && strtolower($this->serverParams['HTTPS']) !== 'off')
|| (!empty($this->serverParams['HTTP_X_FORWARDED_PROTO']) && $this->serverParams['HTTP_X_FORWARDED_PROTO'] == 'https')
|| (!empty($this->serverParams['HTTP_X_FORWARDED_PROTO'])
&& $this->serverParams['HTTP_X_FORWARDED_PROTO'] == 'https')
) {
$scheme = 'https';
} else {
Expand Down Expand Up @@ -362,7 +363,7 @@ public function setEnv(ParametersInterface $env)
* Return the parameter container responsible for env parameters or a single parameter value.
*
* @param string|null $name Parameter name to retrieve, or null to get the whole container.
* @param mixed|null $default Default value to use when the parameter is missing. * @return \Zend\Stdlib\ParametersInterface
* @param mixed|null $default Default value to use when the parameter is missing.
* @return \Zend\Stdlib\ParametersInterface|mixed
*/
public function getEnv($name = null, $default = null)
Expand Down Expand Up @@ -507,7 +508,8 @@ protected function detectBaseUrl()
$basename = basename($filename);
if ($basename) {
$path = ($phpSelf ? trim($phpSelf, '/') : '');
$baseUrl .= substr($path, 0, strpos($path, $basename)) . $basename;
$basePos = strpos($path, $basename) ?: 0;
$baseUrl .= substr($path, 0, $basePos) . $basename;
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/Client/CurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public function testSetConfigInvalidConfig($config)
*/
public function testSettingInvalidCurlOption()
{
if (version_compare(PHP_VERSION, 7, 'gte')) {
$this->markTestSkipped('Test is invalid for PHP version 7');
}

$config = array(
'adapter' => 'Zend\Http\Client\Adapter\Curl',
'curloptions' => array(CURLOPT_CLOSEPOLICY => true),
Expand Down
4 changes: 2 additions & 2 deletions test/Header/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testDateFromTimeStringCreatesValidDateHeader()
$this->assertInstanceOf('Zend\Http\Header\Date', $dateHeader);

$date = new \DateTime(null, new \DateTimeZone('GMT'));
$interval = $dateHeader->date()->diff($date, true);
$interval = $dateHeader->date()->diff($date, 1);

$this->assertSame('+12 hours 00 minutes 00 seconds', $interval->format('%R%H hours %I minutes %S seconds'));
}
Expand All @@ -50,7 +50,7 @@ public function testDateFromTimestampCreatesValidDateHeader()
$this->assertInstanceOf('Zend\Http\Header\Date', $dateHeader);

$date = new \DateTime(null, new \DateTimeZone('GMT'));
$interval = $dateHeader->date()->diff($date, true);
$interval = $dateHeader->date()->diff($date, 1);

$this->assertSame('+12 hours 00 minutes 00 seconds', $interval->format('%R%H hours %I minutes %S seconds'));
}
Expand Down

0 comments on commit b44104c

Please sign in to comment.