@@ -64,6 +64,10 @@ var retrieveFile = handlerExec(retrieveFileHandlers);
6464retrieveFileHandlers . push ( function ( path ) {
6565 // Trim the path to make sure there is no extra whitespace.
6666 path = path . trim ( ) ;
67+ if ( / ^ f i l e : / . test ( path ) ) {
68+ // existsSync/readFileSync can't handle file protocol, but once stripped, it works
69+ path = path . replace ( / f i l e : \/ \/ ( \w : \\ | \/ ) / , '' ) ;
70+ }
6771 if ( path in fileContentsCache ) {
6872 return fileContentsCache [ path ] ;
6973 }
@@ -91,12 +95,18 @@ retrieveFileHandlers.push(function(path) {
9195} ) ;
9296
9397// Support URLs relative to a directory, but be careful about a protocol prefix
94- // in case we are in the browser (i.e. directories may start with "http://")
98+ // in case we are in the browser (i.e. directories may start with "http://" or "file:///" )
9599function supportRelativeURL ( file , url ) {
96100 if ( ! file ) return url ;
97101 var dir = path . dirname ( file ) ;
98102 var match = / ^ \w + : \/ \/ [ ^ \/ ] * / . exec ( dir ) ;
99103 var protocol = match ? match [ 0 ] : '' ;
104+ var startPath = dir . slice ( protocol . length ) ;
105+ if ( protocol && / ^ \/ \w \: / . test ( startPath ) ) {
106+ // handle file:///C:/ paths
107+ protocol += '/' ;
108+ return protocol + path . resolve ( dir . slice ( protocol . length ) , url ) . replace ( / \\ / g, '/' ) ;
109+ }
100110 return protocol + path . resolve ( dir . slice ( protocol . length ) , url ) ;
101111}
102112
0 commit comments