Skip to content

Commit

Permalink
Merge pull request #161 from gabesullice/undefined-uri-template-vars
Browse files Browse the repository at this point in the history
Do not expand undefined URI template variables.
  • Loading branch information
nyamsprod authored Feb 29, 2020
2 parents a12b206 + bbbad37 commit 3dd2732
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion 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) {
$parts[] = $this->expandVariable($variable, $expression['operator'], $joiner, $useQuery);
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 3dd2732

Please sign in to comment.