Bug 1290527 - Fix a parsing issue for sourcemapped locations on Windows. r=jsantell
--- a/devtools/client/shared/components/frame.js
+++ b/devtools/client/shared/components/frame.js
@@ -1,16 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { DOM: dom, createClass, PropTypes } = require("devtools/client/shared/vendor/react");
-const { getSourceNames, parseURL, isScratchpadScheme } = require("devtools/client/shared/source-utils");
+const { getSourceNames, parseURL,
+ isScratchpadScheme, getSourceMappedFile } = require("devtools/client/shared/source-utils");
const { LocalizationHelper } = require("devtools/client/shared/l10n");
const l10n = new LocalizationHelper("chrome://devtools/locale/components.properties");
const webl10n = new LocalizationHelper("chrome://devtools/locale/webconsole.properties");
module.exports = createClass({
displayName: "Frame",
@@ -176,25 +177,18 @@ module.exports = createClass({
elements.push(
dom.span({ className: "frame-link-function-display-name" },
functionDisplayName)
);
}
}
let displaySource = showFullSourceUrl ? long : short;
- // SourceMapped locations might not be parsed properly by parseURL.
- // Eg: sourcemapped location could be /folder/file.coffee instead of a url
- // and so the url parser would not parse non-url locations properly
- // Check for "/" in displaySource. If "/" is in displaySource,
- // take everything after last "/".
if (isSourceMapped) {
- displaySource = displaySource.lastIndexOf("/") < 0 ?
- displaySource :
- displaySource.slice(displaySource.lastIndexOf("/") + 1);
+ displaySource = getSourceMappedFile(displaySource);
} else if (showEmptyPathAsHost && (displaySource === "" || displaySource === "/")) {
displaySource = host;
}
sourceElements.push(dom.span({
className: "frame-link-filename",
}, displaySource));
--- a/devtools/client/shared/source-utils.js
+++ b/devtools/client/shared/source-utils.js
@@ -294,14 +294,35 @@ function isChromeScheme(location, i = 0)
}
return false;
default:
return false;
}
}
+/**
+ * A utility method to get the file name from a sourcemapped location
+ * The sourcemap location can be in any form. This method returns a
+ * formatted file name for different cases like Windows or OSX.
+ * @param source
+ * @returns String
+ */
+function getSourceMappedFile(source) {
+ // If sourcemapped source is a OSX path, return
+ // the characters after last "/".
+ // If sourcemapped source is a Windowss path, return
+ // the characters after last "\\".
+ if (source.lastIndexOf("/") >= 0) {
+ source = source.slice(source.lastIndexOf("/") + 1);
+ } else if (source.lastIndexOf("\\") >= 0) {
+ source = source.slice(source.lastIndexOf("\\") + 1);
+ }
+ return source;
+}
+
exports.parseURL = parseURL;
exports.getSourceNames = getSourceNames;
exports.isScratchpadScheme = isScratchpadScheme;
exports.isChromeScheme = isChromeScheme;
exports.isContentScheme = isContentScheme;
exports.isDataScheme = isDataScheme;
+exports.getSourceMappedFile = getSourceMappedFile;
--- a/devtools/client/shared/test/unit/test_source-utils.js
+++ b/devtools/client/shared/test/unit/test_source-utils.js
@@ -147,14 +147,30 @@ add_task(function* () {
// Check query with trailing slash
testAbbreviation("http://example.com/foo/?bar=1&baz=2",
"foo",
"http://example.com/foo/",
"example.com");
});
+// Test for source mapped file name
+add_task(function* () {
+ const { getSourceMappedFile } = sourceUtils;
+ const source = "baz.js";
+ const output = getSourceMappedFile(source);
+ equal(output, "baz.js", "correctly formats file name");
+ // Test for OSX file path
+ const source1 = "/foo/bar/baz.js";
+ const output1 = getSourceMappedFile(source1);
+ equal(output1, "baz.js", "correctly formats Linux file path");
+ // Test for Windows file path
+ const source2 = "Z:\\foo\\bar\\baz.js";
+ const output2 = getSourceMappedFile(source2);
+ equal(output2, "baz.js", "correctly formats Windows file path");
+});
+
function testAbbreviation(source, short, long, host) {
let results = sourceUtils.getSourceNames(source);
equal(results.short, short, `${source} has correct "short" name`);
equal(results.long, long, `${source} has correct "long" name`);
equal(results.host, host, `${source} has correct "host" name`);
}