diff --git a/__tests__/pure-utils.js b/__tests__/pure-utils.js index ef914836..15bd9fc8 100644 --- a/__tests__/pure-utils.js +++ b/__tests__/pure-utils.js @@ -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 = { diff --git a/src/pure-utils/pathToAction.js b/src/pure-utils/pathToAction.js index 1759cf0e..41ab9035 100644 --- a/src/pure-utils/pathToAction.js +++ b/src/pure-utils/pathToAction.js @@ -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