Skip to content

Commit

Permalink
[Parser] Values set to null are treated as undefined. Minor short cir…
Browse files Browse the repository at this point in the history
…cuit if improvement to Guzzle\Http\Url
  • Loading branch information
mtdowling committed Jul 12, 2012
1 parent 56c7fa0 commit db66916
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Guzzle/Http/Url.php
Expand Up @@ -271,10 +271,10 @@ public function setPath($path)
if (is_array($path)) {
$this->path = '/' . implode('/', $path);
} else {
$this->path = $path;
if ($this->path != '*' && substr($this->path, 0, 1) != '/') {
$this->path = '/' . $path;
if (substr($path, 0, 1) != '/' && $path != '*') {
$path = '/' . $path;
}
$this->path = $path;
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Guzzle/Parser/UriTemplate/UriTemplate.php
Expand Up @@ -130,7 +130,7 @@ private function expandMatch(array $matches)

foreach ($parsed['values'] as $value) {

if (!array_key_exists($value['value'], $this->variables)) {
if (!array_key_exists($value['value'], $this->variables) || $this->variables[$value['value']] === null) {
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Guzzle/Tests/Parser/UriTemplate/UriTemplateTest.php
Expand Up @@ -24,6 +24,7 @@ public function templateProvider()
'path' => '/foo/bar',
'x' => '1024',
'y' => '768',
'null' => null,
'list' => array('red', 'green', 'blue'),
'keys' => array(
"semi" => ';',
Expand Down Expand Up @@ -103,6 +104,8 @@ public function templateProvider()
array('{&list*}', '&list=red&list=green&list=blue'),
array('{&keys}', '&keys=semi,%3B,dot,.,comma,%2C'),
array('{&keys*}', '&semi=%3B&dot=.&comma=%2C'),
array('{.null}', ''),
array('{.null,var}', '.value'),
// Test that missing expansions are skipped
array('test{&missing*}', 'test'),
// Test that multiple expansions can be set
Expand Down

0 comments on commit db66916

Please sign in to comment.