Skip to content

Commit

Permalink
fix($state): sanity-check state lookups
Browse files Browse the repository at this point in the history
 - Fixes #980
  • Loading branch information
nateabele committed Mar 26, 2014
1 parent 0da45a1 commit 456fd5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
}

function findState(stateOrName, base) {
if (!stateOrName) return undefined;

var isStr = isString(stateOrName),
name = isStr ? stateOrName : stateOrName.name,
path = isRelative(name);
Expand Down Expand Up @@ -1116,7 +1118,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
* @returns {object|array} State configuration object or array of all objects.
*/
$state.get = function (stateOrName, context) {
if (!isDefined(stateOrName)) {
if (arguments.length === 0) {
var list = [];
forEach(states, function(state) { list.push(state.self); });
return list;
Expand Down
6 changes: 6 additions & 0 deletions test/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,12 @@ describe('state', function () {
];
expect(list.map(function(state) { return state.name; })).toEqual(names);
}));

it("should return undefined on invalid state query", inject(function ($state) {
expect($state.get(null)).toBeNull();
expect($state.get(false)).toBeNull();
expect($state.get(undefined)).toBeNull();
}));
});

describe('url handling', function () {
Expand Down

0 comments on commit 456fd5a

Please sign in to comment.