diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Angular.js | 17 | ||||
| -rw-r--r-- | src/Resource.js | 13 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/Angular.js b/src/Angular.js index 6e5786ec..2d4b1671 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -853,6 +853,23 @@ function toKeyValue(obj) { return parts.length ? parts.join('&') : ''; } + +/** + * we need our custom mehtod because encodeURIComponent is too agressive and doesn't follow + * http://www.ietf.org/rfc/rfc2396.txt with regards to the character set (pchar) allowed in path + * segments + */ +function encodeUriSegment(val) { + return encodeURIComponent(val). + replace(/%40/gi, '@'). + replace(/%3A/gi, ':'). + replace(/%26/gi, '&'). + replace(/%3D/gi, '='). + replace(/%2B/gi, '+'). + replace(/%24/g, '$'). + replace(/%2C/gi, ','); +} + /** * @workInProgress * @ngdoc directive diff --git a/src/Resource.js b/src/Resource.js index e801d200..f748fb5a 100644 --- a/src/Resource.js +++ b/src/Resource.js @@ -13,19 +13,20 @@ function Route(template, defaults) { Route.prototype = { url: function(params) { - var path = []; - var self = this; - var url = this.template; + var self = this, + url = this.template, + encodedVal; + params = params || {}; forEach(this.urlParams, function(_, urlParam){ - var value = params[urlParam] || self.defaults[urlParam] || ""; - url = url.replace(new RegExp(":" + urlParam + "(\\W)"), encodeURIComponent(value) + "$1"); + encodedVal = encodeUriSegment(params[urlParam] || self.defaults[urlParam] || "") + url = url.replace(new RegExp(":" + urlParam + "(\\W)"), encodedVal + "$1"); }); url = url.replace(/\/?#$/, ''); var query = []; forEachSorted(params, function(value, key){ if (!self.urlParams[key]) { - query.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); + query.push(encodeUriSegment(key) + '=' + encodeUriSegment(value)); } }); url = url.replace(/\/*$/, ''); |
