diff options
| author | Igor Minar | 2011-02-10 17:57:42 -0800 |
|---|---|---|
| committer | Igor Minar | 2011-02-10 17:57:42 -0800 |
| commit | e9ce22592aaf36ce57c4eaa6202842d9f383d172 (patch) | |
| tree | bf5b88c77e2bc9cec11ed29894615a58caa1922a | |
| parent | 4f6fe1d479e91842d0e679d46b6acfff85459af4 (diff) | |
| download | angular.js-e9ce22592aaf36ce57c4eaa6202842d9f383d172.tar.bz2 | |
$resource should encode url params with encodeURIComponent
| -rw-r--r-- | src/Resource.js | 4 | ||||
| -rw-r--r-- | test/ResourceSpec.js | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/Resource.js b/src/Resource.js index c6777c67..e801d200 100644 --- a/src/Resource.js +++ b/src/Resource.js @@ -19,13 +19,13 @@ Route.prototype = { params = params || {}; forEach(this.urlParams, function(_, urlParam){ var value = params[urlParam] || self.defaults[urlParam] || ""; - url = url.replace(new RegExp(":" + urlParam + "(\\W)"), value + "$1"); + url = url.replace(new RegExp(":" + urlParam + "(\\W)"), encodeURIComponent(value) + "$1"); }); url = url.replace(/\/?#$/, ''); var query = []; forEachSorted(params, function(value, key){ if (!self.urlParams[key]) { - query.push(encodeURI(key) + '=' + encodeURI(value)); + query.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); } }); url = url.replace(/\/*$/, ''); diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 8b78df12..d61282ea 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -40,6 +40,14 @@ describe("resource", function() { R.get({a:4, b:5, c:6}); }); + it('should correctly encode url params', function(){ + var R = resource.route('/Path/:a'); + xhr.expectGET('/Path/foo%231').respond({}); + xhr.expectGET('/Path/doh!%40foo?bar=baz%231').respond({}); + R.get({a: 'foo#1'}); + R.get({a: 'doh!@foo', bar: 'baz#1'}); + }); + it("should build resource with default param", function(){ xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'abc'}); var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05}); |
