Skip to content
Closed
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
11 changes: 11 additions & 0 deletions packages/app/src/context/file/path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ describe("file path helpers", () => {
expect(stripQueryAndHash("a/b.ts")).toBe("a/b.ts")
})

test("should NOT decode literal %20 in raw Windows path", () => {
const path = createPathHelpers(() => "D:\\First%20Second")
// Input is a raw path, not a file:// URL — %20 is a literal folder name character
expect(path.normalize("D:\\First%20Second\\file.txt")).toBe("file.txt")
})

test("should decode %20 in file:// URL path", () => {
const path = createPathHelpers(() => "/home/user/My Documents")
expect(path.normalize("file:///home/user/My%20Documents/file.txt")).toBe("file.txt")
})

test("unquotes git escaped octal path strings", () => {
expect(unquoteGitPath('"a/\\303\\251.txt"')).toBe("a/\u00e9.txt")
expect(unquoteGitPath('"plain\\nname"')).toBe("plain\nname")
Expand Down
9 changes: 8 additions & 1 deletion packages/app/src/context/file/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ export function createPathHelpers(scope: () => string) {
const normalize = (input: string) => {
const root = scope()

let path = unquoteGitPath(decodeFilePath(stripQueryAndHash(stripFileProtocol(input))))
// Only decode percent-encoding for file:// URLs — raw filesystem paths may
// contain literal % characters (e.g. D:\First%20Second) that must be preserved.
const isUrl = input.startsWith("file://") || input.startsWith("file:\\\\")
let path = unquoteGitPath(
isUrl
? decodeFilePath(stripQueryAndHash(stripFileProtocol(input)))
: stripQueryAndHash(stripFileProtocol(input)),
)

// Separator-agnostic prefix stripping for Cygwin/native Windows compatibility
// Only case-insensitive on Windows (drive letter or UNC paths)
Expand Down
Loading