mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
$resource should encode url params with encodeURIComponent
This commit is contained in:
parent
4f6fe1d479
commit
e9ce22592a
2 changed files with 10 additions and 2 deletions
|
|
@ -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(/\/*$/, '');
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
|
|
|
|||
Loading…
Reference in a new issue