Skip to content

Commit

Permalink
Improve PR #161
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Feb 29, 2020
1 parent 318aba7 commit 49c6163
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

All Notable changes to `League\Uri` will be documented in this file

## Next - TBD

### Added

- None

### Fixed

- Bugfix `UriTemplate::expand` to comply with expansion rules for undefined variables [#161](https://github.com/thephpleague/uri/pull/161) thanks [Gabe Sullice](https://github.com/gabesullice)

### Deprecated

- Nothing

### Remove

- Hard dependencies on the `ext-mbstring` and the `ext-fileinfo` PHP extensions [#154](https://github.com/thephpleague/uri/pull/154) thanks [Nicolas Grekas](https://github.com/nicolas-grekas)

## 6.2.0 - 2020-02-08

### Added
Expand Down
11 changes: 7 additions & 4 deletions src/UriTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use League\Uri\Exceptions\SyntaxError;
use League\Uri\Exceptions\TemplateCanNotBeExpanded;
use function array_filter;
use function array_key_exists;
use function array_keys;
use function explode;
use function gettype;
Expand Down Expand Up @@ -402,9 +403,7 @@ 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);
}
$parts[] = $this->expandVariable($variable, $expression['operator'], $joiner, $useQuery);
}

$nullFilter = static function ($value): bool {
Expand All @@ -430,7 +429,11 @@ private function expandExpression(array $foundExpression): string
*/
private function expandVariable(array $variable, string $operator, string $joiner, bool $useQuery): string
{
$value = $this->variables[$variable['name']] ?? '';
if (!array_key_exists($variable['name'], $this->variables)) {
return '';
}

$value = $this->variables[$variable['name']];
$arguments = [$value, $variable, $operator];
$method = 'expandString';
if (is_array($value)) {
Expand Down

0 comments on commit 49c6163

Please sign in to comment.