File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import {Observable} from 'rxjs/Observable';
1313import { Observer } from 'rxjs/Observer' ;
1414import { isSuccess , getResponseURL } from '../http_utils' ;
1515
16- const XSSI_PREFIX = ')]}\',\n' ;
16+ const XSSI_PREFIX = / ^ \) \] \} ' , ? \n / ;
1717
1818/**
1919 * Creates connections using `XMLHttpRequest`. Given a fully-qualified
@@ -46,9 +46,7 @@ export class XHRConnection implements Connection {
4646 // IE10)
4747 let body = isPresent ( _xhr . response ) ? _xhr . response : _xhr . responseText ;
4848 // Implicitly strip a potential XSSI prefix.
49- if ( isString ( body ) && body . startsWith ( XSSI_PREFIX ) ) {
50- body = body . substring ( XSSI_PREFIX . length ) ;
51- }
49+ if ( isString ( body ) ) body = body . replace ( XSSI_PREFIX , '' ) ;
5250 let headers = Headers . fromResponseHeaderString ( _xhr . getAllResponseHeaders ( ) ) ;
5351
5452 let url = getResponseURL ( _xhr ) ;
Original file line number Diff line number Diff line change @@ -472,6 +472,17 @@ export function main() {
472472 existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
473473 } ) ) ;
474474
475+ it ( 'should strip XSSI prefixes' , inject ( [ AsyncTestCompleter ] , ( async : AsyncTestCompleter ) => {
476+ var conn = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) , new ResponseOptions ( ) ) ;
477+ conn . response . subscribe ( ( res : Response ) => {
478+ expect ( res . text ( ) ) . toBe ( '{json: "object"}' ) ;
479+ async . done ( ) ;
480+ } ) ;
481+ existingXHRs [ 0 ] . setStatusCode ( 200 ) ;
482+ existingXHRs [ 0 ] . setResponseText ( ')]}\'\n{json: "object"}' ) ;
483+ existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
484+ } ) ) ;
485+
475486 it ( 'should strip XSSI prefixes' , inject ( [ AsyncTestCompleter ] , ( async : AsyncTestCompleter ) => {
476487 var conn = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) , new ResponseOptions ( ) ) ;
477488 conn . response . subscribe ( ( res : Response ) => {
@@ -491,7 +502,7 @@ export function main() {
491502 async . done ( ) ;
492503 } ) ;
493504 existingXHRs [ 0 ] . setStatusCode ( 404 ) ;
494- existingXHRs [ 0 ] . setResponseText ( ')]}\', \n{json: "object"}' ) ;
505+ existingXHRs [ 0 ] . setResponseText ( ')]}\'\n{json: "object"}' ) ;
495506 existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
496507 } ) ) ;
497508
You can’t perform that action at this time.
0 commit comments