File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -538,10 +538,16 @@ export function fetch(input, init) {
538538
539539 xhr . onload = function ( ) {
540540 var options = {
541- status : xhr . status ,
542541 statusText : xhr . statusText ,
543542 headers : parseHeaders ( xhr . getAllResponseHeaders ( ) || '' )
544543 }
544+ // This check if specifically for when a user fetches a file locally from the file system
545+ // Only if the status is out of a normal range
546+ if ( request . url . startsWith ( 'file://' ) && ( xhr . status < 200 || xhr . status > 599 ) ) {
547+ options . status = 200 ;
548+ } else {
549+ options . status = xhr . status ;
550+ }
545551 options . url = 'responseURL' in xhr ? xhr . responseURL : options . headers . get ( 'X-Request-URL' )
546552 var body = 'response' in xhr ? xhr . response : xhr . responseText
547553 setTimeout ( function ( ) {
@@ -632,4 +638,4 @@ if (!g.fetch) {
632638 g . Headers = Headers
633639 g . Request = Request
634640 g . Response = Response
635- }
641+ }
Original file line number Diff line number Diff line change @@ -647,7 +647,15 @@ exercise.forEach(function(exerciseMode) {
647647 new Response ( '' , { status : i } )
648648 } )
649649 }
650+ // A fetch with the url of a `file://` scheme may have a status 0 or
651+ // similar in some operating systems. In the event that a status is found outside
652+ // the standard range of 200-599, and the url start with `file://`
653+ // the status should return 200
654+ assert . doesNotThrow ( function ( ) {
655+ new Request ( '' , { status : 0 , request : { url : 'file://path/to/local/file' } } )
656+ } )
650657 } )
658+
651659 test ( 'creates Headers object from raw headers' , function ( ) {
652660 var r = new Response ( '{"foo":"bar"}' , { headers : { 'content-type' : 'application/json' } } )
653661 assert . equal ( r . headers instanceof Headers , true )
You can’t perform that action at this time.
0 commit comments