Skip to content

Commit 91f75ae

Browse files
committed
fix($urlMatcherFactory): detect injected functions
Correctly detects injectable functions annotated as arrays when registering new type definitions.
1 parent 67be0bd commit 91f75ae

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/urlMatcherFactory.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -675,12 +675,16 @@ function $UrlMatcherFactory() {
675675
return this;
676676
}];
677677

678+
// To ensure proper order of operations in object configuration, and to allow internal
679+
// types to be overridden, `flushTypeQueue()` waits until `$urlMatcherFactory` is injected
680+
// before actually wiring up and assigning type definitions
678681
function flushTypeQueue() {
679682
forEach(typeQueue, function(type) {
680683
if (UrlMatcher.prototype.$types[type.name]) {
681684
throw new Error("A type named '" + type.name + "' has already been defined.");
682685
}
683-
var def = new Type(isFunction(type.def) ? injector.invoke(type.def) : type.def);
686+
var isAnnotated = isFunction(type.def) || isArray(type.def);
687+
var def = new Type(isAnnotated ? injector.invoke(type.def) : type.def);
684688
UrlMatcher.prototype.$types[type.name] = def;
685689
});
686690
}

test/urlMatcherFactorySpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,17 @@ describe("urlMatcherFactory", function () {
227227
expect($umf.type("myType").decode()).toBe($stateParams);
228228
}));
229229

230+
it("should accept annotated function definitions", inject(function ($stateParams) {
231+
$umf.type("myAnnotatedType", ['$stateParams', function(s) {
232+
return {
233+
decode: function() {
234+
return s;
235+
}
236+
};
237+
}]);
238+
expect($umf.type("myAnnotatedType").decode()).toBe($stateParams);
239+
}));
240+
230241
it("should match built-in types", function () {
231242
var m = new UrlMatcher("/{foo:int}/{flag:bool}");
232243
expect(m.exec("/1138/1")).toEqual({ foo: 1138, flag: true });

0 commit comments

Comments
 (0)