Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: uppercase windows drive letters #151

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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