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 = '') =>
44 / ( j s o n | x m l | y a m l | t e x t ) \b / . test ( contentType ) ;
55
66function 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+ }
1214 }
1315 return jsYaml . load ( body ) ;
1416}
Original file line number Diff line number Diff line change @@ -469,6 +469,23 @@ describe('http', () => {
469469 expect ( resSerialize . data ) . toBe ( body ) ;
470470 } ) ;
471471 } ) ;
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+ } ) ;
472489 } ) ;
473490
474491 describe ( 'shouldDownloadAsText' , ( ) => {
You can’t perform that action at this time.
0 commit comments