-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Don't pass 'undefined'
for missing optional parameters
#4064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
decodeURIComponent(undefined) is "undefined"
location={{ pathname: '/foo' }} | ||
component={(props) => { | ||
expect(props).toEqual({ | ||
params: { foo: 'foo', bar: undefined }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or do we rather expect { foo: 'foo' }
here, without the bar
key?
@@ -23,7 +23,7 @@ const getMatcher = (pattern, exactly) => { | |||
|
|||
const parseParams = (pattern, match, keys) => | |||
match.slice(1).reduce((params, value, index) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may want to add filter(value => value !== undefined)
before the reduce
call to prevent "missing" params to be defined as param properties at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter sounds good to me.
@@ -23,7 +23,7 @@ const getMatcher = (pattern, exactly) => { | |||
|
|||
const parseParams = (pattern, match, keys) => | |||
match.slice(1).reduce((params, value, index) => { | |||
params[keys[index].name] = decodeURIComponent(value) | |||
params[keys[index].name] = value === undefined ? undefined : decodeURIComponent(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and leave this modification out
undefined
'undefined'
for missing optional parameters
PR updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Is this getting released soon? |
decodeURIComponent(undefined)
is"undefined"