Skip to content

Commit 3bfd75a

Browse files
fix($urlMatcherFactory): add 'any' Type for non-encoding non-url params
- Allow arbitrary data be passed to a state as a parameter. Do not attempt to encode/decode the parameter. - Store the location of the parameter: either "search", "path", or "config" (non-url params are "config") Closes #1562
1 parent 027f1fc commit 3bfd75a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/state.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
6868
ownParams: function(state) {
6969
var params = state.url && state.url.params || new $$UMFP.ParamSet();
7070
forEach(state.params || {}, function(config, id) {
71-
if (!params[id]) params[id] = new $$UMFP.Param(id, null, config);
71+
if (!params[id]) params[id] = new $$UMFP.Param(id, null, config, "config");
7272
});
7373
return params;
7474
},

src/urlMatcherFactory.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,13 @@ function $UrlMatcherFactory() {
611611
is: angular.isObject,
612612
equals: angular.equals,
613613
pattern: /[^/]*/
614+
},
615+
any: { // does not encode/decode
616+
encode: angular.identity,
617+
decode: angular.identity,
618+
is: angular.identity,
619+
equals: angular.equals,
620+
pattern: /.*/
614621
}
615622
};
616623

@@ -878,7 +885,7 @@ function $UrlMatcherFactory() {
878885
this.Param = function Param(id, type, config, location) {
879886
var self = this;
880887
config = unwrapShorthand(config);
881-
type = getType(config, type);
888+
type = getType(config, type, location);
882889
var arrayMode = getArrayMode();
883890
type = arrayMode ? type.$asArray(arrayMode, location === "search") : type;
884891
if (type.name === "string" && !arrayMode && location === "path" && config.value === undefined)
@@ -896,10 +903,10 @@ function $UrlMatcherFactory() {
896903
return config;
897904
}
898905

899-
function getType(config, urlType) {
906+
function getType(config, urlType, location) {
900907
if (config.type && urlType) throw new Error("Param '"+id+"' has two type configurations.");
901908
if (urlType) return urlType;
902-
if (!config.type) return $types.string;
909+
if (!config.type) return (location === "config" ? $types.any : $types.string);
903910
return config.type instanceof Type ? config.type : new Type(config.type);
904911
}
905912

@@ -960,13 +967,14 @@ function $UrlMatcherFactory() {
960967
extend(this, {
961968
id: id,
962969
type: type,
970+
location: location,
963971
array: arrayMode,
964-
config: config,
965972
squash: squash,
966973
replace: replace,
967974
isOptional: isOptional,
968-
dynamic: undefined,
969975
value: $value,
976+
dynamic: undefined,
977+
config: config,
970978
toString: toString
971979
});
972980
};
@@ -1013,7 +1021,7 @@ function $UrlMatcherFactory() {
10131021
param = self[key];
10141022
val = paramValues[key];
10151023
isOptional = !val && param.isOptional;
1016-
result = result && (isOptional || param.type.is(val));
1024+
result = result && (isOptional || !!param.type.is(val));
10171025
});
10181026
return result;
10191027
},

0 commit comments

Comments
 (0)