Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions lib/source-map/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ define(function (require, exports, module) {
};

/**
* Returns the original source content. The only argument is
* the url of the original source file. Returns null if no
* original source content is availible.
* Returns the original source content. The only argument is the url of the
* original source file. Returns null if no original source content is
* availible.
*/
SourceMapConsumer.prototype.sourceContentFor =
function SourceMapConsumer_sourceContentFor(aSource) {
Expand All @@ -318,10 +318,21 @@ define(function (require, exports, module) {

var url;
if (this.sourceRoot
&& (url = util.urlParse(this.sourceRoot))
&& (!url.path || url.path == "/")
&& this._sources.has("/" + aSource)) {
return this.sourcesContent[this._sources.indexOf("/" + aSource)];
&& (url = util.urlParse(this.sourceRoot))) {
// XXX: file:// URIs and absolute paths lead to unexpected behavior for
// many users. We can help them out when they expect file:// URIs to
// behave like it would if they were running a local HTTP server. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
if (url.scheme == "file"
&& this._sources.has(fileUriAbsPath)) {
return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
}

if ((!url.path || url.path == "/")
&& this._sources.has("/" + aSource)) {
return this.sourcesContent[this._sources.indexOf("/" + aSource)];
}
}

throw new Error('"' + aSource + '" is not in the SourceMap.');
Expand Down
15 changes: 15 additions & 0 deletions test/source-map/test-source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,19 @@ define(function (require, exports, module) {
assert.equal(map.sourceContentFor("/a"), "foo");
};

exports['test bug 885597'] = function (assert, util) {
var map = new SourceMapConsumer({
"version": 3,
"file": "foo.js",
"sourceRoot": "file:///Users/AlGore/Invented/The/Internet/",
"sources": ["/a"],
"names": [],
"mappings": "AACA",
"sourcesContent": ["foo"]
});

var s = map.sources[0];
assert.equal(map.sourceContentFor(s), "foo");
};

});