Skip to content

Commit 456fd5a

Browse files
committed
fix($state): sanity-check state lookups
- Fixes #980
1 parent 0da45a1 commit 456fd5a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/state.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
133133
}
134134

135135
function findState(stateOrName, base) {
136+
if (!stateOrName) return undefined;
137+
136138
var isStr = isString(stateOrName),
137139
name = isStr ? stateOrName : stateOrName.name,
138140
path = isRelative(name);
@@ -1116,7 +1118,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
11161118
* @returns {object|array} State configuration object or array of all objects.
11171119
*/
11181120
$state.get = function (stateOrName, context) {
1119-
if (!isDefined(stateOrName)) {
1121+
if (arguments.length === 0) {
11201122
var list = [];
11211123
forEach(states, function(state) { list.push(state.self); });
11221124
return list;

test/stateSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,12 @@ describe('state', function () {
726726
];
727727
expect(list.map(function(state) { return state.name; })).toEqual(names);
728728
}));
729+
730+
it("should return undefined on invalid state query", inject(function ($state) {
731+
expect($state.get(null)).toBeNull();
732+
expect($state.get(false)).toBeNull();
733+
expect($state.get(undefined)).toBeNull();
734+
}));
729735
});
730736

731737
describe('url handling', function () {

0 commit comments

Comments
 (0)