From 15a73bf7b1c27034bf9f3e66a9d1c3eeff996336 Mon Sep 17 00:00:00 2001 From: Wilfred van der Deijl Date: Mon, 30 May 2016 09:56:24 +0200 Subject: [PATCH 1/3] fix relative references to subdirs on windows for example reference to `./subdir/otherfile.html` from `c:\somedir\somefile.html` having windows directories with back-slahses (\) confused the logic in get_reference_representations_relative to determine relative paths between two files --- tool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool.js b/tool.js index e571d21..c7f0e44 100644 --- a/tool.js +++ b/tool.js @@ -10,7 +10,7 @@ module.exports = (function() { }; var dirname_with_sep = function(path) { - return Path.dirname(path) + '/'; + return Path.dirname(path).replace(/\\/g, '/') + '/'; } var join_path_url = function (prefix, path) { From 02145daaad3adc0e9e48037d07933238b9ceba89 Mon Sep 17 00:00:00 2001 From: Wilfred van der Deijl Date: Mon, 30 May 2016 10:53:34 +0200 Subject: [PATCH 2/3] test for relative windows paths --- test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test.js b/test.js index 7a7f198..b544d62 100644 --- a/test.js +++ b/test.js @@ -1211,6 +1211,31 @@ describe('gulp-rev-all', function () { }); + it('windows path', function () { + + var base = 'c:\\first\\second'; + + var file = new Gutil.File({ + path: 'c:\\first\\second\\third\\index.html', + base: base + }); + + var fileReference = new Gutil.File({ + path: 'c:\\first\\second\\third\\fourth\\other.html', + base: base + }); + + file.revPathOriginal = file.path; + fileReference.revPathOriginal = fileReference.path; + + var references = Tool.get_reference_representations_relative(fileReference, file); + + references.length.should.equal(2); + references[0].should.equal('fourth/other.html'); + references[1].should.equal('./fourth/other.html'); + + }); + }); describe('should resolve references that have 1 traversals', function () { From c762b5060fd093ed6f9b281af3b86c05d4f0b18c Mon Sep 17 00:00:00 2001 From: Wilfred van der Deijl Date: Mon, 30 May 2016 11:28:28 +0200 Subject: [PATCH 3/3] execute windows relative paths tests only on windows due to usage of nodejs Paths.dirname I could not get the windows tests to work on Linux/Mac as the \ character is not used as path separator by Paths --- test.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/test.js b/test.js index b544d62..7af948e 100644 --- a/test.js +++ b/test.js @@ -1211,30 +1211,32 @@ describe('gulp-rev-all', function () { }); - it('windows path', function () { + if (/^win/.test(process.platform)) { + it('windows path', function () { - var base = 'c:\\first\\second'; + var base = 'c:\\first\\second'; - var file = new Gutil.File({ - path: 'c:\\first\\second\\third\\index.html', - base: base - }); + var file = new Gutil.File({ + path: 'c:\\first\\second\\third\\index.html', + base: base + }); - var fileReference = new Gutil.File({ - path: 'c:\\first\\second\\third\\fourth\\other.html', - base: base - }); + var fileReference = new Gutil.File({ + path: 'c:\\first\\second\\third\\fourth\\other.html', + base: base + }); - file.revPathOriginal = file.path; - fileReference.revPathOriginal = fileReference.path; + file.revPathOriginal = file.path; + fileReference.revPathOriginal = fileReference.path; - var references = Tool.get_reference_representations_relative(fileReference, file); + var references = Tool.get_reference_representations_relative(fileReference, file); - references.length.should.equal(2); - references[0].should.equal('fourth/other.html'); - references[1].should.equal('./fourth/other.html'); + references.length.should.equal(2); + references[0].should.equal('fourth/other.html'); + references[1].should.equal('./fourth/other.html'); - }); + }); + } });