Skip to content

Commit 4229886

Browse files
authored
Merge pull request #201 from kriszyp/file-protocol-support
Add support for proper handling of file protocol (in windows)
2 parents 646092f + 3bd9b4b commit 4229886

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

source-map-support.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ var retrieveFile = handlerExec(retrieveFileHandlers);
6464
retrieveFileHandlers.push(function(path) {
6565
// Trim the path to make sure there is no extra whitespace.
6666
path = path.trim();
67+
if (/^file:/.test(path)) {
68+
// existsSync/readFileSync can't handle file protocol, but once stripped, it works
69+
path = path.replace(/file:\/\/(\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:///")
9599
function 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

Comments
 (0)