From b2f46251aca76c8568ee7d4bab54edbc9d7a186a Mon Sep 17 00:00:00 2001 From: pavelgj Date: Tue, 8 Jan 2013 14:19:40 -0800 Subject: fix(ngResource): correct leading slash removal. Fixed an issues with ngResource param substitution where it was incorrectly removing leading slash when param was followed by a non-slash character. Ex: '/:foo/:bar.baz/:aux' params = { foo: 'aaa', bar: undefined, aux: undefined } The above params were incorrectly producing '/aaa.baz' but now it results in '/aaa/.baz'.--- src/ngResource/resource.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/ngResource/resource.js') diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index b2bf86cb..7e26a6a4 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -311,7 +311,14 @@ angular.module('ngResource', ['ng']). encodedVal = encodeUriSegment(val); url = url.replace(new RegExp(":" + urlParam + "(\\W)", "g"), encodedVal + "$1"); } else { - url = url.replace(new RegExp("/?:" + urlParam + "(\\W)", "g"), '$1'); + url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W)", "g"), function(match, + leadingSlashes, tail) { + if (tail.charAt(0) == '/') { + return tail; + } else { + return leadingSlashes + tail; + } + }); } }); url = url.replace(/\/?#$/, ''); -- cgit v1.2.3