diff --git a/apps/desktop/src/wsl/wslPathParsing.test.ts b/apps/desktop/src/wsl/wslPathParsing.test.ts index 41e358227e1e..dd750164b381 100644 --- a/apps/desktop/src/wsl/wslPathParsing.test.ts +++ b/apps/desktop/src/wsl/wslPathParsing.test.ts @@ -1,11 +1,9 @@ import { describe, it, expect } from "vite-plus/test"; import { - DISTRO_NAME_PATTERN, extractDistroFromUncPath, isValidDistroName, parseWslDistroList, - resolveWslHomeUncPath, resolveWslPickFolderDefaultPath, wslUncPathToLinuxPath, } from "./wslPathParsing.ts"; @@ -116,29 +114,6 @@ describe("wslUncPathToLinuxPath", () => { }); }); -describe("resolveWslHomeUncPath", () => { - const distros = [ - { name: "Debian", isDefault: true, version: 2 as const }, - { name: "Ubuntu", isDefault: false, version: 2 as const }, - ]; - - it("uses the configured distro when one is selected", () => { - expect(resolveWslHomeUncPath({ distro: "Ubuntu" }, distros)).toBe( - "\\\\wsl.localhost\\Ubuntu\\home", - ); - }); - - it("uses the actual default distro when config uses the WSL default", () => { - expect(resolveWslHomeUncPath({ distro: null }, distros)).toBe( - "\\\\wsl.localhost\\Debian\\home", - ); - }); - - it("omits the default path when no default distro is known", () => { - expect(resolveWslHomeUncPath({ distro: null }, [])).toBeNull(); - }); -}); - describe("resolveWslPickFolderDefaultPath", () => { const config = { distro: null }; const distros = [{ name: "Debian", isDefault: true, version: 2 as const }]; @@ -184,23 +159,22 @@ describe("resolveWslPickFolderDefaultPath", () => { }); }); -describe("DISTRO_NAME_PATTERN / isValidDistroName", () => { +describe("isValidDistroName", () => { it("accepts common distro names", () => { for (const name of ["Ubuntu", "Ubuntu-22.04", "kali-linux", "Debian", "Ubuntu 22.04"]) { - expect(DISTRO_NAME_PATTERN.test(name)).toBe(true); expect(isValidDistroName(name)).toBe(true); } }); it("rejects names with trailing whitespace, hyphen, or dot", () => { for (const name of ["Ubuntu ", "Ubuntu-", "Ubuntu."]) { - expect(DISTRO_NAME_PATTERN.test(name)).toBe(false); + expect(isValidDistroName(name)).toBe(false); } }); it("rejects names containing control or shell-meta characters", () => { for (const name of ["bad\nname", "bad\tname", "bad/name", "bad!name", "bad;name"]) { - expect(DISTRO_NAME_PATTERN.test(name)).toBe(false); + expect(isValidDistroName(name)).toBe(false); } }); }); diff --git a/apps/desktop/src/wsl/wslPathParsing.ts b/apps/desktop/src/wsl/wslPathParsing.ts index edbab81f6dc2..baae217c823d 100644 --- a/apps/desktop/src/wsl/wslPathParsing.ts +++ b/apps/desktop/src/wsl/wslPathParsing.ts @@ -10,7 +10,7 @@ export interface WslConfig { // Literal space — \s would also match \n/\t/\r and corrupt UNC paths like \\wsl.localhost\\... // Trailing char must also be \w so hand-edited config like "Ubuntu " / "Ubuntu-" / "Ubuntu." rejects. -export const DISTRO_NAME_PATTERN = /^\w(?:[\w \-.]*\w)?$/; +const DISTRO_NAME_PATTERN = /^\w(?:[\w \-.]*\w)?$/; export function parseWslDistroList(stdout: Buffer): readonly WslDistro[] { const hasUtf16Bom = stdout.length >= 2 && stdout[0] === 0xff && stdout[1] === 0xfe; @@ -61,10 +61,7 @@ export function wslUncPathToLinuxPath(windowsPath: string): string | null { return `/${rest.split("\\").filter(Boolean).join("/")}`; } -export function resolveWslHomeUncPath( - config: WslConfig, - distros: readonly WslDistro[], -): string | null { +function resolveWslHomeUncPath(config: WslConfig, distros: readonly WslDistro[]): string | null { const distroName = config.distro ?? distros.find((distro) => distro.isDefault)?.name ?? null; return distroName ? `\\\\wsl.localhost\\${distroName}\\home` : null; }