Skip to content

Commit

Permalink
0 should be allowed as an expandable value (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine Wattier <wattier@adobe.com>
  • Loading branch information
AntoineWattier and Antoine Wattier authored Aug 27, 2023
1 parent a6a9904 commit 2573d77
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/UriTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private static function expandMatch(array $matches, array $variables): string
}

if ($actuallyUseQuery) {
if (!$expanded && $joiner !== '&') {
if ($expanded === '' && $joiner !== '&') {
$expanded = $value['value'];
} else {
$expanded = \sprintf('%s=%s', $value['value'], $expanded);
Expand Down
2 changes: 2 additions & 0 deletions tests/UriTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function templateProvider(): array
'x' => '1024',
'y' => 768,
'null' => null,
'zero' => 0,
'list' => ['red', 'green', 'blue'],
'keys' => [
'semi' => ';',
Expand Down Expand Up @@ -56,6 +57,7 @@ public function templateProvider(): array
['{/var}', '/value'],
['{/var,x}/here', '/value/1024/here'],
['{;x,y}', ';x=1024;y=768'],
['{;zero}', ';zero=0'],
['{;x,y,empty}', ';x=1024;y=768;empty'],
['{?x,y}', '?x=1024&y=768'],
['{?x,y,empty}', '?x=1024&y=768&empty='],
Expand Down

0 comments on commit 2573d77

Please sign in to comment.