Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit dc1a67c

Browse files
committed
fix(ngResource): fix query url params encoding
Strictly encode query url parameters
1 parent f8fbd72 commit dc1a67c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/ngResource/resource.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -431,16 +431,20 @@ angular.module('ngResource', ['ng']).
431431
}
432432
if (!(new RegExp("^\\d+$").test(param)) && param &&
433433
(new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
434-
urlParams[param] = true;
434+
urlParams[param] = { isQueryParam: (new RegExp("\\?(?:.*)\\:" + param + "(?:\\W|$)")).test(url) };
435435
}
436436
});
437437
url = url.replace(/\\:/g, ':');
438438

439439
params = params || {};
440-
forEach(self.urlParams, function(_, urlParam) {
440+
forEach(self.urlParams, function(paramInfo, urlParam) {
441441
val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
442442
if (angular.isDefined(val) && val !== null) {
443-
encodedVal = encodeUriSegment(val);
443+
if (paramInfo.isQueryParam === true) {
444+
encodedVal = encodeUriQuery(val, true);
445+
} else {
446+
encodedVal = encodeUriSegment(val);
447+
}
444448
url = url.replace(new RegExp(":" + urlParam + "(\\W|$)", "g"), function(match, p1) {
445449
return encodedVal + p1;
446450
});

0 commit comments

Comments
 (0)