From bc8f03a78a6d4908927e4f7245644f793784faa1 Mon Sep 17 00:00:00 2001 From: Tom Willoughby Date: Tue, 21 Jan 2020 13:22:23 +0000 Subject: [PATCH 1/3] Add unc paths to isAbsolute regex --- lib/path/index.js | 2 +- lib/path/tests/index.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/path/index.js b/lib/path/index.js index 7c7fb723e..771761a8a 100644 --- a/lib/path/index.js +++ b/lib/path/index.js @@ -14,7 +14,7 @@ var isAbsolute = * @returns {boolean} `true` if path is absolute */ path.isAbsolute = function isAbsolute(path) { - return /^(?:\/|\w+:)/.test(path); + return /^(?:\/|\w+:|\\\\\w+)/.test(path); }; var normalize = diff --git a/lib/path/tests/index.js b/lib/path/tests/index.js index 9c23bc969..3cc0ad8aa 100644 --- a/lib/path/tests/index.js +++ b/lib/path/tests/index.js @@ -10,6 +10,8 @@ tape.test("path", function(test) { test.notOk(path.isAbsolute("some\\path\\file.js"), "should identify relative windows paths"); test.notOk(path.isAbsolute("some/path/file.js"), "should identify relative unix paths"); + test.ok(path.isAbsolute("\\\\some-unc\\path\\file.js"), "should identify windows unc paths"); + var paths = [ { actual: "X:\\some\\..\\.\\path\\\\file.js", From 6729a7b7ec087fb1a8456bdd4acd04470223004c Mon Sep 17 00:00:00 2001 From: Tom Willoughby Date: Tue, 21 Jan 2020 13:35:00 +0000 Subject: [PATCH 2/3] Allow unc paths to be resolved and normalized --- lib/path/index.js | 9 ++++++++- lib/path/tests/index.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/path/index.js b/lib/path/index.js index 771761a8a..b2da0e07d 100644 --- a/lib/path/index.js +++ b/lib/path/index.js @@ -24,6 +24,13 @@ var normalize = * @returns {string} Normalized path */ path.normalize = function normalize(path) { + var firstTwoCharacters = path.substring(0,2); + var uncPrefix = ""; + if (firstTwoCharacters === "\\\\") { + uncPrefix = firstTwoCharacters; + path = path.substring(2); + } + path = path.replace(/\\/g, "/") .replace(/\/{2,}/g, "/"); var parts = path.split("/"), @@ -44,7 +51,7 @@ path.normalize = function normalize(path) { else ++i; } - return prefix + parts.join("/"); + return uncPrefix + prefix + parts.join("/"); }; /** diff --git a/lib/path/tests/index.js b/lib/path/tests/index.js index 3cc0ad8aa..6b6155667 100644 --- a/lib/path/tests/index.js +++ b/lib/path/tests/index.js @@ -47,6 +47,20 @@ tape.test("path", function(test) { }, { actual: "/.././path//file.js", normal: "/path/file.js" + }, { + actual: "\\\\some-unc\\path\\file.js", + normal: "\\\\some-unc/path/file.js", + resolve: { + origin: "\\\\some-unc\\path\\origin.js", + expected: "\\\\some-unc/path/file.js" + } + }, { + actual: "\\\\some-unc\\path\\..\\file.js", + normal: "\\\\some-unc/file.js", + resolve: { + origin: "\\\\some-unc\\path\\..\\origin.js", + expected: "\\\\some-unc/file.js" + } } ]; From 82c1b16ef40208cad8e6256e4721acfebed46891 Mon Sep 17 00:00:00 2001 From: Tom Willoughby Date: Thu, 25 Jun 2020 15:56:34 +0100 Subject: [PATCH 3/3] Remove trailing whitespace --- lib/path/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/path/index.js b/lib/path/index.js index b2da0e07d..8c7ee12fb 100644 --- a/lib/path/index.js +++ b/lib/path/index.js @@ -30,7 +30,7 @@ path.normalize = function normalize(path) { uncPrefix = firstTwoCharacters; path = path.substring(2); } - + path = path.replace(/\\/g, "/") .replace(/\/{2,}/g, "/"); var parts = path.split("/"),