Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions apps/desktop/src/wsl/wslPathParsing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,15 @@ describe("wslUncPathToLinuxPath", () => {
expect(wslUncPathToLinuxPath("\\\\wsl.localhost\\Debian\\")).toBe("/");
});

it("maps UNC paths of distros whose names start or end with a dot or hyphen", () => {
for (const name of ["Ubuntu-", "Ubuntu.", ".Ubuntu", "-Ubuntu"]) {
expect(wslUncPathToLinuxPath(`\\\\wsl.localhost\\${name}\\home\\josh`)).toBe("/home/josh");
}
});
Comment on lines +80 to +84

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These cases repeat the same name validation already tested at the lower isValidDistroName layer. Could you remove this wrapper test and keep the cases at that layer?

Suggested change
it("maps UNC paths of distros whose names start or end with a dot or hyphen", () => {
for (const name of ["Ubuntu-", "Ubuntu.", ".Ubuntu", "-Ubuntu"]) {
expect(wslUncPathToLinuxPath(`\\\\wsl.localhost\\${name}\\home\\josh`)).toBe("/home/josh");
}
});

Posted via Macroscope — Test Signal


it("rejects invalid distro names and non-WSL paths", () => {
expect(wslUncPathToLinuxPath("\\\\wsl.localhost\\bad!name\\home")).toBeNull();
expect(wslUncPathToLinuxPath("\\\\wsl.localhost\\..\\home")).toBeNull();
expect(wslUncPathToLinuxPath("C:\\Users\\Josh\\repo")).toBeNull();
});
});
Expand Down Expand Up @@ -107,9 +114,13 @@ describe("resolveWslPickFolderDefaultPath", () => {
});

describe("isValidDistroName", () => {
it("rejects names with trailing whitespace, hyphen, or dot", () => {
for (const name of ["Ubuntu ", "Ubuntu-", "Ubuntu."]) {
expect(isValidDistroName(name)).toBe(false);
it("rejects names with trailing whitespace", () => {
expect(isValidDistroName("Ubuntu ")).toBe(false);
});

it("accepts names WSL registers with a leading or trailing dot or hyphen", () => {
for (const name of ["Ubuntu-", "Ubuntu.", ".Ubuntu", "-Ubuntu"]) {
expect(isValidDistroName(name)).toBe(true);
}
});

Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/wsl/wslPathParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export interface WslConfig {
}

// Literal spaces only; \s would accept controls and corrupt UNC distro paths.
const DISTRO_NAME_PATTERN = /^\w(?:[\w \-.]*\w)?$/;
// "." and ".." would be path segments in a UNC path, not distro names.
const DISTRO_NAME_PATTERN = /^(?!\.{1,2}$)[\w.-](?:[\w .-]*[\w.-])?$/;

export function parseWslDistroList(stdout: Buffer): readonly WslDistro[] {
const hasUtf16Bom = stdout.length >= 2 && stdout[0] === 0xff && stdout[1] === 0xfe;
Expand Down
Loading