diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index 7e858e6ca..9114c3c48 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -496,9 +496,9 @@ Type.prototype.$asArray = function(mode, isSearch) { return new ArrayType(this, mode); function ArrayType(type, mode) { - function bindTo(thisObj, callback) { + function bindTo(type, callbackName) { return function() { - return callback.apply(thisObj, arguments); + return type[callbackName].apply(type, arguments); }; } @@ -537,10 +537,10 @@ Type.prototype.$asArray = function(mode, isSearch) { }; } - this.encode = arrayHandler(bindTo(this, type.encode)); - this.decode = arrayHandler(bindTo(this, type.decode)); - this.is = arrayHandler(bindTo(this, type.is), true); - this.equals = arrayEqualsHandler(bindTo(this, type.equals)); + this.encode = arrayHandler(bindTo(type, 'encode')); + this.decode = arrayHandler(bindTo(type, 'decode')); + this.is = arrayHandler(bindTo(type, 'is'), true); + this.equals = arrayEqualsHandler(bindTo(type, 'equals')); this.pattern = type.pattern; this.$arrayMode = mode; } diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js old mode 100644 new mode 100755 index 1e77fb22f..5a2e7dc7d --- a/test/urlMatcherFactorySpec.js +++ b/test/urlMatcherFactorySpec.js @@ -402,6 +402,24 @@ describe("UrlMatcher", function () { }); }); +describe("urlMatcherFactoryProvider", function () { + describe(".type()", function () { + var m; + beforeEach(module('ui.router.util', function($urlMatcherFactoryProvider) { + $urlMatcherFactoryProvider.type("myType", {}, function() { + return { decode: function() { return 'decoded'; } + }; + }); + m = new UrlMatcher("/test?{foo:myType}"); + })); + + it("should handle arrays properly with config-time custom type definitions", inject(function ($stateParams) { + expect(m.exec("/test", {foo: '1'})).toEqual({ foo: 'decoded' }); + expect(m.exec("/test", {foo: ['1', '2']})).toEqual({ foo: ['decoded', 'decoded'] }); + })); + }); +}); + describe("urlMatcherFactory", function () { var $umf;