From 807394095b991357225a03d5fed81fea5c9a1abe Mon Sep 17 00:00:00 2001 From: joshkurz Date: Fri, 26 Apr 2013 17:31:56 -0400 Subject: fix(Angular.js): handle duplicate params in parseKeyValue/toKeyValue parseKeyValue and toKeyValue can now handle duplicate values in the query. ``` ?x=1&x=2 <-> {x:[1,2]} ``` The algorithm looks like: 1)parseKeyValue looks for presence of obj[key] 2)detects and replaces obj[key] with [obj[key],val] 3)then pushes more duplicates if necessary 4)toKeyValue decodes array correctly 5)(not changed)$location.search({param: 'key'}) still replaces if necessary 6)(not changed)$location.search({param: ['key1', 'key2']}) sets the url with duplicates BREAKING CHANGE: Before this change: - `parseKeyValue` only took the last key overwriting all the previous keys; - `toKeyValue` joined the keys together in a comma delimited string. This was deemed buggy behavior. If your server relied on this behavior then either the server should be fixed or a simple serialization of the array should be done on the client before passing it to $location. --- src/ng/location.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/ng') diff --git a/src/ng/location.js b/src/ng/location.js index 40d39282..a0f03a8e 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -344,7 +344,8 @@ LocationHashbangInHtml5Url.prototype = * * Change search part when called with parameter and return `$location`. * - * @param {string|object=} search New search params - string or hash object + * @param {string|Object.|Object.>} search New search params - string or hash object. Hash object + * may contain an array of values, which will be decoded as duplicates in the url. * @param {string=} paramValue If `search` is a string, then `paramValue` will override only a * single search parameter. If the value is `null`, the parameter will be deleted. * -- cgit v1.2.3