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 2 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
12 changes: 9 additions & 3 deletions src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { normalizeWindowsPath } from "./_internal";
const _UNC_REGEX = /^[/\\]{2}/;
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;

// Force POSIX contants
Expand Down Expand Up @@ -212,9 +213,14 @@ export const extname: typeof path.extname = function (p) {

// relative
export const relative: typeof path.relative = function (from, to) {
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");

const _from = resolve(from)
pi0 marked this conversation as resolved.
Show resolved Hide resolved
.replace(_ROOT_FOLDER_RE, "$1")
.replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase())
.split("/");
const _to = resolve(to)
.replace(_ROOT_FOLDER_RE, "$1")
.replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase())
.split("/");
const _fromCopy = [..._from];
for (const segment of _fromCopy) {
if (_to[0] !== segment) {
Expand Down
1 change: 1 addition & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
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