Skip to content

Commit

Permalink
fix: uppercase windows drive letters (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jan 10, 2024
1 parent 04a0aee commit cbd6095
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/_internal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;

// Util to normalize windows paths to posix
export function normalizeWindowsPath(input = "") {
if (!input || !input.includes("\\")) {
if (!input) {
return input;
}
return input.replace(/\\/g, "/");
return input
.replace(/\\/g, "/")
.replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
}
11 changes: 6 additions & 5 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ runTest("normalizeWindowsPath", normalizeWindowsPath, {
"/foo/bar": "/foo/bar",

// Windows
"c:\\foo\\bar": "c:/foo/bar",
"c:\\foo\\bar": "C:/foo/bar",
"\\foo\\bar": "/foo/bar",
".\\foo\\bar": "./foo/bar",
});
Expand Down Expand Up @@ -179,11 +179,11 @@ runTest("normalize", normalize, {
"C:\\temp\\..": "C:/",
"C:\\temp\\\\foo\\bar\\..\\": "C:/temp/foo/",
"C:////temp\\\\/\\/\\/foo/bar": "C:/temp/foo/bar",
"c:/windows/nodejs/path": "c:/windows/nodejs/path",
"c:/windows/../nodejs/path": "c:/nodejs/path",
"c:/windows/nodejs/path": "C:/windows/nodejs/path",
"c:/windows/../nodejs/path": "C:/nodejs/path",

"c:\\windows\\nodejs\\path": "c:/windows/nodejs/path",
"c:\\windows\\..\\nodejs\\path": "c:/nodejs/path",
"c:\\windows\\nodejs\\path": "C:/windows/nodejs/path",
"c:\\windows\\..\\nodejs\\path": "C:/nodejs/path",

"/windows\\unix/mixed": "/windows/unix/mixed",
"\\windows//unix/mixed": "/windows/unix/mixed",
Expand Down Expand Up @@ -245,6 +245,7 @@ runTest("relative", relative, [

// Windows
["C:\\orandea\\test\\aaa", "C:\\orandea\\impl\\bbb", "../../impl/bbb"],
["C:\\orandea\\test\\aaa", "c:\\orandea\\impl\\bbb", "../../impl/bbb"],
["C:\\", "C:\\foo\\bar", "foo/bar"],
["C:\\foo", "C:\\", ".."],
[
Expand Down

0 comments on commit cbd6095

Please sign in to comment.