Skip to content

Commit 36775a7

Browse files
authored
Update to handle multiple query parameters
Updating the parser to handle multiple query parameters with the same name. There is currently no RFC spec for situations like this, but most server side implementations handle this situation where you have id=1&id=2&id=3 in the query string.
1 parent 0963f09 commit 36775a7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

angular-url-parser.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,21 @@ angular
2121

2222
for( i = 0; i < queries.length; i++ ) {
2323
split = queries[i].split('=');
24-
searchObject[split[0]] = split[1];
24+
// handle query strings such as id=1&id=2&id=3
25+
if(searchObject.hasOwnProperty(split[0])) {
26+
var currentVal = searchObject[split[0]];
27+
var valueList;
28+
if(!angular.isArray(currentVal)){
29+
valueList = [];
30+
valueList.push(currentVal);
31+
} else {
32+
valueList = currentVal;
33+
}
34+
valueList.push(split[1]);
35+
searchObject[split[0]] = valueList;
36+
} else {
37+
searchObject[split[0]] = split[1];
38+
}
2539
}
2640

2741
return {

0 commit comments

Comments
 (0)