fix(desktop): clamp UNC picker navigation

This commit is contained in:
LukeParkerDev 2026-06-08 08:17:01 +10:00
parent cb6be7a1b4
commit 81ed6c5618
2 changed files with 17 additions and 1 deletions

View file

@ -15,6 +15,8 @@ import {
treePathWithin,
currentPickerSuggestions,
displayPickerPath,
pickerParent,
pickerRoot,
} from "./directory-picker-domain"
test("maps server directory entries into Pierre paths", () => {
@ -96,6 +98,13 @@ test("displays paths using the selected server path format", () => {
expect(displayPickerPath("/home/luke/repos", "~/repos", "/home/luke")).toBe("~/repos")
})
test("treats the server share prefix as the UNC root", () => {
expect(pickerRoot("//Server/Share/repo/src")).toBe("//Server/Share")
expect(pickerRoot("\\\\Server\\Share\\repo\\src")).toBe("//Server/Share")
expect(pickerParent("//Server/Share")).toBe("//Server/Share")
expect(pickerParent("//Server/Share/repo")).toBe("//Server/Share")
})
test("exposes autocomplete results only for their source query", () => {
const result = { query: "/repo/src", items: ["/repo/src/index.ts"] }
expect(currentPickerSuggestions(result, "/repo/src")).toEqual(result.items)

View file

@ -207,7 +207,11 @@ export function joinPickerPath(base: string | undefined, relative: string) {
export function pickerRoot(input: string) {
const value = normalizePickerDrive(input)
if (value.startsWith("//")) return "//"
if (value.startsWith("//")) {
const [server, share] = value.slice(2).split("/")
if (server && share) return `//${server}/${share}`
return "//"
}
if (value.startsWith("/")) return "/"
if (/^[A-Za-z]:\//.test(value)) return value.slice(0, 3)
return ""
@ -215,8 +219,11 @@ export function pickerRoot(input: string) {
export function pickerParent(input: string) {
const value = trimPickerPath(input)
const root = pickerRoot(value)
if (value === root) return value
if (value === "/" || value === "//" || /^[A-Za-z]:\/$/.test(value)) return value
const index = value.lastIndexOf("/")
if (index < root.length) return root
if (index <= 0) return "/"
if (index === 2 && /^[A-Za-z]:/.test(value)) return value.slice(0, 3)
return value.slice(0, index)