Skip to content

Commit

Permalink
Fixed: NULL parameters aren't excluded from generation of route
Browse files Browse the repository at this point in the history
  • Loading branch information
ElGigi committed Dec 15, 2021
1 parent 58f3667 commit ac7a0fd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. This projec
to [Semantic Versioning] (http://semver.org/). For change log format,
use [Keep a Changelog] (http://keepachangelog.com/).

## [2.0.1] - 2021-12-15

### Fixed

- `NULL` parameters aren't excluded from generation of route

## [2.0.0] - 2021-09-08

No changes were introduced since the previous beta 3 release.
Expand Down
1 change: 1 addition & 0 deletions src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ public function generate(array $parameters = [], int &$nbUsed = 0): string
{
$this->compile();

$parameters = array_filter($parameters, fn($value) => null !== $value);
$path =
(string)preg_replace_callback(
static::REGEX_ATTRIBUTE,
Expand Down
1 change: 1 addition & 0 deletions tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ public function testGenerateWithOptionalPart()
$route = new Route('/my-path/{foo}[/{bar}]');

$this->assertEquals('/my-path/value1', $route->generate(['foo' => 'value1']));
$this->assertEquals('/my-path/value1', $route->generate(['foo' => 'value1', 'bar' => null]));
$this->assertEquals('/my-path/value1/value2', $route->generate(['foo' => 'value1', 'bar' => 'value2']));
}

Expand Down

0 comments on commit ac7a0fd

Please sign in to comment.