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

Commit 246a667

Browse files
committed
fix($http): won't parse single space response
Rails sends a single space response instead of empty headers, this change will not attempt to parse the response
1 parent 0c19482 commit 246a667

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ng/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ function $HttpProvider() {
782782
function transformResponse(response) {
783783
// make a copy since the response must be cacheable
784784
var resp = extend({}, response);
785-
if (!response.data) {
785+
if (!response.data || response.data === ' ') {
786786
resp.data = response.data;
787787
} else {
788788
resp.data = transformData(response.data, response.headers, config.transformResponse);

test/ng/httpSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,17 @@ describe('$http', function() {
11331133
expect(callback.mostRecentCall.args[0]).toEqual('');
11341134
});
11351135

1136+
it('should not attempt to deserialize json for a blank response whose header contains application/json', function() {
1137+
//per http spec for Content-Type, HEAD request should return a Content-Type header
1138+
//set to what the content type would have been if a get was sent
1139+
$httpBackend.expect('GET', '/url').respond(' ', {'Content-Type': 'application/json'});
1140+
$http({method: 'GET', url: '/url'}).success(callback);
1141+
$httpBackend.flush();
1142+
1143+
expect(callback).toHaveBeenCalledOnce();
1144+
expect(callback.mostRecentCall.args[0]).toEqual(' ');
1145+
});
1146+
11361147
it('should not deserialize tpl beginning with ng expression', function() {
11371148
$httpBackend.expect('GET', '/url').respond('{{some}}');
11381149
$http.get('/url').success(callback);

0 commit comments

Comments
 (0)