File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed
src/http/serializers/response Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -4,11 +4,13 @@ export const shouldDownloadAsText = (contentType = '') =>
4
4
/ ( j s o n | x m l | y a m l | t e x t ) \b / . test ( contentType ) ;
5
5
6
6
function parseBody ( body , contentType ) {
7
- if (
8
- contentType &&
9
- ( contentType . indexOf ( 'application/json' ) === 0 || contentType . indexOf ( '+json' ) > 0 )
10
- ) {
11
- return JSON . parse ( body ) ;
7
+ if ( contentType ) {
8
+ if ( contentType . indexOf ( 'application/json' ) === 0 || contentType . indexOf ( '+json' ) > 0 ) {
9
+ return JSON . parse ( body ) ;
10
+ }
11
+ if ( contentType . indexOf ( 'application/xml' ) === 0 || contentType . indexOf ( '+xml' ) > 0 ) {
12
+ return body ;
13
+ }
12
14
}
13
15
return jsYaml . load ( body ) ;
14
16
}
Original file line number Diff line number Diff line change @@ -469,6 +469,23 @@ describe('http', () => {
469
469
expect ( resSerialize . data ) . toBe ( body ) ;
470
470
} ) ;
471
471
} ) ;
472
+
473
+ test ( 'should not parse xml response' , ( ) => {
474
+ const headers = { 'Content-Type' : 'application/xml' } ;
475
+ const body = '<Pet><name>cat: with: colon: and: spaces</name></Pet>' ;
476
+ const mockPool = mockAgent . get ( 'http://swagger.io' ) ;
477
+ mockPool . intercept ( { path : '/' } ) . reply ( 200 , body , { headers } ) ;
478
+
479
+ return fetch ( 'http://swagger.io' )
480
+ . then ( ( _res ) =>
481
+ // eslint-disable-line no-undef
482
+ serializeResponse ( _res , 'https://swagger.io' )
483
+ )
484
+ . then ( ( resSerialize ) => {
485
+ expect ( resSerialize . body ) . toBe ( body ) ;
486
+ expect ( resSerialize . parseError ) . toBeUndefined ( ) ;
487
+ } ) ;
488
+ } ) ;
472
489
} ) ;
473
490
474
491
describe ( 'shouldDownloadAsText' , ( ) => {
You can’t perform that action at this time.
0 commit comments