diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index cea6ffb63..db1ad11ba 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(thisObj, type, callbackName) { return function() { - return callback.apply(thisObj, arguments); + return type[callbackName].apply(thisObj, 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(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.pattern = type.pattern; this.$arrayMode = mode; } diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js old mode 100644 new mode 100755 index b705b7ed9..44e735461 --- a/test/urlMatcherFactorySpec.js +++ b/test/urlMatcherFactorySpec.js @@ -402,6 +402,31 @@ 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;