From 381fb98fdf73a99b757766cd27bfad8b2fc19499 Mon Sep 17 00:00:00 2001 From: Luke Page Date: Tue, 17 Dec 2013 23:06:51 +0000 Subject: [PATCH] normalize the base path as well as the filename for sourcemaps. Fixes #1736 --- lib/less/source-map-output.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/less/source-map-output.js b/lib/less/source-map-output.js index 0eb80c5c9..131464f93 100644 --- a/lib/less/source-map-output.js +++ b/lib/less/source-map-output.js @@ -8,7 +8,9 @@ this._sourceMapFilename = options.sourceMapFilename; this._outputFilename = options.outputFilename; this._sourceMapURL = options.sourceMapURL; - this._sourceMapBasepath = options.sourceMapBasepath; + if (this._sourceMapBasepath) { + this._sourceMapBasepath = options.sourceMapBasepath.replace(/\\/g, '/'); + } this._sourceMapRootpath = options.sourceMapRootpath; this._outputSourceFiles = options.outputSourceFiles; this._sourceMapGeneratorConstructor = options.sourceMapGenerator || require("source-map").SourceMapGenerator; @@ -22,13 +24,14 @@ }; tree.sourceMapOutput.prototype.normalizeFilename = function(filename) { + filename = filename.replace(/\\/g, '/'); if (this._sourceMapBasepath && filename.indexOf(this._sourceMapBasepath) === 0) { - filename = filename.substring(this._sourceMapBasepath.length); - if (filename.charAt(0) === '\\' || filename.charAt(0) === '/') { - filename = filename.substring(1); - } + filename = filename.substring(this._sourceMapBasepath.length); + if (filename.charAt(0) === '\\' || filename.charAt(0) === '/') { + filename = filename.substring(1); + } } - return (this._sourceMapRootpath || "") + filename.replace(/\\/g, '/'); + return (this._sourceMapRootpath || "") + filename; }; tree.sourceMapOutput.prototype.add = function(chunk, fileInfo, index, mapLines) {