Skip to content

Commit

Permalink
Do not expand undefined URI template variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabesullice committed Feb 28, 2020
1 parent a12b206 commit 742e128
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/UriTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ private function expandExpression(array $foundExpression): string
$parts = [];
/** @var array{name:string, modifier:string, position:string} $variable */
foreach ($expression['variables'] as $variable) {
if (isset($this->variables[$variable['name']])) {
$parts[] = $this->expandVariable($variable, $expression['operator'], $joiner, $useQuery);
}
}

$nullFilter = static function ($value): bool {
Expand Down
1 change: 1 addition & 0 deletions tests/UriTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public function templateExpansionProvider(): iterable
['{;x,y,empty}', ';x=1024;y=768;empty'],
['{?x,y}', '?x=1024&y=768'],
['{?x,y,empty}', '?x=1024&y=768&empty='],
['{?x,y,undef}', '?x=1024&y=768'],
['?fixed=yes{&x}', '?fixed=yes&x=1024'],
['{&x,y,empty}', '&x=1024&y=768&empty='],
],
Expand Down

0 comments on commit 742e128

Please sign in to comment.