From 456fd5aec9ea507518927bfabd62b4afad4cf714 Mon Sep 17 00:00:00 2001 From: Nate Abele Date: Wed, 26 Mar 2014 15:36:17 -0400 Subject: [PATCH] fix($state): sanity-check state lookups - Fixes #980 --- src/state.js | 4 +++- test/stateSpec.js | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/state.js b/src/state.js index 3b44e7d83..905b89e8f 100644 --- a/src/state.js +++ b/src/state.js @@ -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); @@ -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; diff --git a/test/stateSpec.js b/test/stateSpec.js index 3829a3699..7dcae9f3f 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -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 () {