Skip to content

Commit

Permalink
Fix empty strings in default parameters breaking navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
TehShrike committed Nov 5, 2016
1 parent f355511 commit 2abf936
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [5.14.1](https://github.com/TehShrike/abstract-state-router/releases/tag/v5.14.1)

- bug fix: empty strings in default parameters would cause the state router to stop cold without any error message

# [5.14.0](https://github.com/TehShrike/abstract-state-router/releases/tag/v5.14.0)

- functional: replaced the `defaultQuerystringParameters` property on states with `defaultParameters`, which applies to both querystring and route parameters. If you don't specify `defaultParameters`, `defaultQuerystringParameters` will be checked too (though it will now apply to route parameters as well). [#91](https://github.com/TehShrike/abstract-state-router/issues/91)
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ module.exports = function StateProvider(makeRenderer, rootElement, stateRouterOp
var state = prototypalStateHolder.get(newStateName)
var defaultParams = state.defaultParameters || state.defaultQuerystringParameters || {}
var needToApplyDefaults = Object.keys(defaultParams).some(function missingParameterValue(param) {
return !parameters[param]
return typeof parameters[param] === 'undefined'
})

if (needToApplyDefaults) {
Expand Down
25 changes: 25 additions & 0 deletions test/default-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,28 @@ test('default parameters on parent states should apply to child state routes', f
testWithPropertyName('defaultParameters')
testWithPropertyName('defaultQuerystringParameters')
})

test('empty string is a valid default parameter', function(t) {
var state = getTestState(t)
var stateRouter = state.stateRouter

stateRouter.addState({
name: 'state',
route: '/state',
template: {},
defaultParameters: {
someParam: ''
},
querystringParameters: [ 'someParam' ],
activate: function(context) {
t.equal(context.parameters.someParam, '')
t.equal(state.location.get(), '/state?someParam=')

t.end()
}
})

stateRouter.go('state')
}, {
timeout: 1000
})

0 comments on commit 2abf936

Please sign in to comment.