summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/context/file
diff options
context:
space:
mode:
authorAdam <[email protected]>2026-02-10 10:12:17 -0600
committerAdam <[email protected]>2026-02-10 10:15:37 -0600
commit70c794e9139af1c1a2c43979d8f5e499a1587189 (patch)
tree72aedf7a8113d07fe803cf5678d7da683be2dc81 /packages/app/src/context/file
parent3929f0b5bd5535fc601b8ce9092929af1adb6629 (diff)
downloadopencode-70c794e9139af1c1a2c43979d8f5e499a1587189.tar.gz
opencode-70c794e9139af1c1a2c43979d8f5e499a1587189.zip
fix(app): regressions
Diffstat (limited to 'packages/app/src/context/file')
-rw-r--r--packages/app/src/context/file/path.test.ts16
-rw-r--r--packages/app/src/context/file/path.ts7
2 files changed, 14 insertions, 9 deletions
diff --git a/packages/app/src/context/file/path.test.ts b/packages/app/src/context/file/path.test.ts
index 95247c08b..f2a3c44b6 100644
--- a/packages/app/src/context/file/path.test.ts
+++ b/packages/app/src/context/file/path.test.ts
@@ -108,7 +108,7 @@ describe("encodeFilePath", () => {
const url = new URL(fileUrl)
expect(url.protocol).toBe("file:")
expect(url.pathname).toContain("README.bs.md")
- expect(result).toBe("/D%3A/dev/projects/opencode/README.bs.md")
+ expect(result).toBe("/D:/dev/projects/opencode/README.bs.md")
})
test("should handle mixed separator path (Windows + Unix)", () => {
@@ -118,7 +118,7 @@ describe("encodeFilePath", () => {
const fileUrl = `file://${result}`
expect(() => new URL(fileUrl)).not.toThrow()
- expect(result).toBe("/D%3A/dev/projects/opencode/README.bs.md")
+ expect(result).toBe("/D:/dev/projects/opencode/README.bs.md")
})
test("should handle Windows path with spaces", () => {
@@ -146,7 +146,7 @@ describe("encodeFilePath", () => {
const fileUrl = `file://${result}`
expect(() => new URL(fileUrl)).not.toThrow()
- expect(result).toBe("/C%3A/")
+ expect(result).toBe("/C:/")
})
test("should handle Windows relative path with backslashes", () => {
@@ -177,7 +177,7 @@ describe("encodeFilePath", () => {
const fileUrl = `file://${result}`
expect(() => new URL(fileUrl)).not.toThrow()
- expect(result).toBe("/c%3A/users/test/file.txt")
+ expect(result).toBe("/c:/users/test/file.txt")
})
})
@@ -193,7 +193,7 @@ describe("encodeFilePath", () => {
const result = encodeFilePath(windowsPath)
// Should convert to forward slashes and add leading /
expect(result).not.toContain("\\")
- expect(result).toMatch(/^\/[A-Za-z]%3A\//)
+ expect(result).toMatch(/^\/[A-Za-z]:\//)
})
test("should handle relative paths the same on all platforms", () => {
@@ -237,7 +237,7 @@ describe("encodeFilePath", () => {
const result = encodeFilePath(alreadyNormalized)
// Should not add another leading slash
- expect(result).toBe("/D%3A/path/file.txt")
+ expect(result).toBe("/D:/path/file.txt")
expect(result).not.toContain("//D")
})
@@ -246,7 +246,7 @@ describe("encodeFilePath", () => {
const result = encodeFilePath(justDrive)
const fileUrl = `file://${result}`
- expect(result).toBe("/D%3A")
+ expect(result).toBe("/D:")
expect(() => new URL(fileUrl)).not.toThrow()
})
@@ -256,7 +256,7 @@ describe("encodeFilePath", () => {
const fileUrl = `file://${result}`
expect(() => new URL(fileUrl)).not.toThrow()
- expect(result).toBe("/C%3A/Users/test/")
+ expect(result).toBe("/C:/Users/test/")
})
test("should handle very long paths", () => {
diff --git a/packages/app/src/context/file/path.ts b/packages/app/src/context/file/path.ts
index e1d47c644..859fdc040 100644
--- a/packages/app/src/context/file/path.ts
+++ b/packages/app/src/context/file/path.ts
@@ -90,9 +90,14 @@ export function encodeFilePath(filepath: string): string {
}
// Encode each path segment (preserving forward slashes as path separators)
+ // Keep the colon in Windows drive letters (`/C:/...`) so downstream file URL parsers
+ // can reliably detect drives.
return normalized
.split("/")
- .map((segment) => encodeURIComponent(segment))
+ .map((segment, index) => {
+ if (index === 1 && /^[A-Za-z]:$/.test(segment)) return segment
+ return encodeURIComponent(segment)
+ })
.join("/")
}