This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +12
-1
lines changed
2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ function defaultHttpResponseTransform(data, headers) {
11
11
// strip json vulnerability protection prefix
12
12
data = data . replace ( JSON_PROTECTION_PREFIX , '' ) ;
13
13
var contentType = headers ( 'Content-Type' ) ;
14
- if ( ( contentType && contentType . indexOf ( APPLICATION_JSON ) === 0 ) ||
14
+ if ( ( contentType && contentType . indexOf ( APPLICATION_JSON ) === 0 && data . trim ( ) ) ||
15
15
( JSON_START . test ( data ) && JSON_END . test ( data ) ) ) {
16
16
data = fromJson ( data ) ;
17
17
}
Original file line number Diff line number Diff line change @@ -1133,6 +1133,17 @@ describe('$http', function() {
1133
1133
expect ( callback . mostRecentCall . args [ 0 ] ) . toEqual ( '' ) ;
1134
1134
} ) ;
1135
1135
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
+
1136
1147
it ( 'should not deserialize tpl beginning with ng expression' , function ( ) {
1137
1148
$httpBackend . expect ( 'GET' , '/url' ) . respond ( '{{some}}' ) ;
1138
1149
$http . get ( '/url' ) . success ( callback ) ;
You can’t perform that action at this time.
0 commit comments