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

Commit ce1f1f9

Browse files
committed
fix(ngResource): don't append number to '$' in url param value when encoding URI
Previously, if a URL parameter value included a $, it would replace the dollar sign with a literal '$1' for mysterious reasons. Using a function rather than a replacement string circumvents this behaviour and produces a more expected result. Closes #6003 Closes #6004
1 parent 8205158 commit ce1f1f9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/ngResource/resource.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,9 @@ angular.module('ngResource', ['ng']).
387387
val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
388388
if (angular.isDefined(val) && val !== null) {
389389
encodedVal = encodeUriSegment(val);
390-
url = url.replace(new RegExp(":" + urlParam + "(\\W|$)", "g"), encodedVal + "$1");
390+
url = url.replace(new RegExp(":" + urlParam + "(\\W|$)", "g"), function(match, p1) {
391+
return encodedVal + p1;
392+
});
391393
} else {
392394
url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W|$)", "g"), function(match,
393395
leadingSlashes, tail) {

test/ngResource/resourceSpec.js

+2
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,11 @@ describe("resource", function() {
178178

179179
$httpBackend.expect('GET', '/Path/foo%231').respond('{}');
180180
$httpBackend.expect('GET', '/Path/doh!@foo?bar=baz%231').respond('{}');
181+
$httpBackend.expect('GET', '/Path/herp$').respond('{}');
181182

182183
R.get({a: 'foo#1'});
183184
R.get({a: 'doh!@foo', bar: 'baz#1'});
185+
R.get({a: 'herp$'});
184186
});
185187

186188

0 commit comments

Comments
 (0)