Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 288b69a

Browse files
committed
fix($http): do not encode special characters @$:, in params
encodeURIComponent is too aggressive and doesn't follow http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path segments so we need this test to make sure that we don't over-encode the params and break stuff like buzz api which uses @self. This is has already been fixed in `$resource`. This commit fixes it in a same way for `$http` as well. BREAKING CHANGE: $http does follow RFC3986 and does not encode special characters like `$@,:` in params. If your application needs to encode these characters, encode them manually, before sending the request.
1 parent 2a21234 commit 288b69a

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/ng/http.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,8 @@ function $HttpProvider() {
818818
if (isObject(v)) {
819819
v = toJson(v);
820820
}
821-
parts.push(encodeURIComponent(key) + '=' +
822-
encodeURIComponent(v));
821+
parts.push(encodeUriQuery(key) + '=' +
822+
encodeUriQuery(v));
823823
});
824824
});
825825
return url + ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&');

test/ng/httpSpec.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('$http', function() {
144144

145145

146146
it('should jsonify objects in params map', inject(function($httpBackend, $http) {
147-
$httpBackend.expect('GET', '/url?a=1&b=%7B%22c%22%3A3%7D').respond('');
147+
$httpBackend.expect('GET', '/url?a=1&b=%7B%22c%22:3%7D').respond('');
148148
$http({url: '/url', params: {a:1, b:{c:3}}, method: 'GET'});
149149
}));
150150

@@ -153,6 +153,17 @@ describe('$http', function() {
153153
$httpBackend.expect('GET', '/url?a=1&a=2&a=3').respond('');
154154
$http({url: '/url', params: {a: [1,2,3]}, method: 'GET'});
155155
}));
156+
157+
158+
it('should not encode @ in url params', function() {
159+
//encodeURIComponent is too agressive and doesn't follow http://www.ietf.org/rfc/rfc3986.txt
160+
//with regards to the character set (pchar) allowed in path segments
161+
//so we need this test to make sure that we don't over-encode the params and break stuff
162+
//like buzz api which uses @self
163+
164+
$httpBackend.expect('GET', '/Path?!do%26h=g%3Da+h&:bar=$baz@1').respond('');
165+
$http({url: '/Path', params: {':bar': '$baz@1', '!do&h': 'g=a h'}, method: 'GET'});
166+
});
156167
});
157168

158169

test/ngResource/resourceSpec.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ describe("resource", function() {
118118
});
119119

120120

121-
// In order to get this passed, we need to fix $http - another breaking change,
122-
// so I'm gonna submit that as a separate CL.
123-
xit('should not encode @ in url params', function() {
121+
it('should not encode @ in url params', function() {
124122
//encodeURIComponent is too agressive and doesn't follow http://www.ietf.org/rfc/rfc3986.txt
125123
//with regards to the character set (pchar) allowed in path segments
126124
//so we need this test to make sure that we don't over-encode the params and break stuff like

0 commit comments

Comments
 (0)