diff options
| author | Igor Minar | 2011-02-16 19:48:21 -0500 | 
|---|---|---|
| committer | Igor Minar | 2011-02-17 23:06:53 -0800 | 
| commit | 9e30baad3feafc82fb2f2011fd3f21909f4ba29e (patch) | |
| tree | 98bceb6601422c859b1f7cf326fdb77385593808 /src | |
| parent | a070ff5ad08450a1eb6375790fc90693d624e283 (diff) | |
| download | angular.js-9e30baad3feafc82fb2f2011fd3f21909f4ba29e.tar.bz2 | |
resources should not over-encode chars in url path
- added encodeUriSegment that properly encodes only those chars
  that URI RFC requires us to encode
- modified Resource to use encodeUriSegment
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(/\/*$/, ''); | 
