Skip to content

Commit

Permalink
Merge pull request #280 from nanaya/fix-null-optional
Browse files Browse the repository at this point in the history
Fix handling of null optional parameter
  • Loading branch information
bakerkretzmar committed Apr 24, 2020
2 parents 1c8d7b1 + 6846a10 commit c490b70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/js/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class Router extends String {
delete this.urlParams[keyName];
}

// The type of the value is undefined; is this param
// The value is null or defined; is this param
// optional or not
if (typeof tagValue === 'undefined') {
if (tagValue == null) {
if (tag.indexOf('?') === -1) {
throw new Error(
"Ziggy Error: '" +
Expand Down
7 changes: 7 additions & 0 deletions tests/js/test.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ describe('route()', function() {
);
});

it('Should skip the optional parameter `slug` when null', function() {
assert.equal(
route('optional', { id: 123, slug: null }),
'http://myapp.dev/optional/123'
);
});

it('Should accept the optional parameter `slug`', function() {
assert.equal(
route('optional', { id: 123, slug: 'news' }),
Expand Down

0 comments on commit c490b70

Please sign in to comment.