Skip to content

Commit

Permalink
Merge pull request #58 from cthierer/fix/parameters-parsed-as-NaN
Browse files Browse the repository at this point in the history
fix($pathToAction): recognize blank string parameters as NaN
  • Loading branch information
faceyspacey authored Aug 4, 2017
2 parents 8fb13d9 + 506a45c commit dea4829
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions __tests__/pure-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ describe('pathToAction(path, routesMap)', () => {
expect(action.payload.param).toEqual(69)
})

it('does not parse a blank string "" as NaN', () => {
const path = '/info'
const routesMap = {
INFO_WILDCARD: { path: '/info(.*)' }
}

const action = pathToAction(path, routesMap)
expect(action.payload[0]).toEqual('')
})

it('parsed path not found and return NOT_FOUND action.type: "@@redux-first-router/NOT_FOUND"', () => {
const path = '/info/foo/bar'
const routesMap = {
Expand Down
4 changes: 3 additions & 1 deletion src/pure-utils/pathToAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export default (
const payload = keys.reduce((payload, key, index) => {
let value = match && match[index + 1] // item at index 0 is the overall match, whereas those after correspond to the key's index

value = !isNaN(value)
value = typeof value === 'string' &&
!value.match(/^\s*$/) &&
!isNaN(value) // check that value is not a blank string, and is numeric
? parseFloat(value) // make sure pure numbers aren't passed to reducers as strings
: value

Expand Down

0 comments on commit dea4829

Please sign in to comment.