diff options
| author | Khang Ha (Kelvin) <[email protected]> | 2026-02-07 05:16:56 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-06 16:16:56 -0600 |
| commit | fde0b39b7c97dacb78cb55f3d963aa54f61650ea (patch) | |
| tree | 066ebb3f0a2716c9e0ee8e72b55239ad249cd5d1 /packages/app/src/context | |
| parent | e9a3cfc083bf480ba2c8aaa585a4e914549e3e56 (diff) | |
| download | opencode-fde0b39b7c97dacb78cb55f3d963aa54f61650ea.tar.gz opencode-fde0b39b7c97dacb78cb55f3d963aa54f61650ea.zip | |
fix: properly encode file URLs with special characters (#12424)
Diffstat (limited to 'packages/app/src/context')
| -rw-r--r-- | packages/app/src/context/file/path.ts | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/packages/app/src/context/file/path.ts b/packages/app/src/context/file/path.ts index ced30d0fd..155f05aaf 100644 --- a/packages/app/src/context/file/path.ts +++ b/packages/app/src/context/file/path.ts @@ -72,12 +72,27 @@ export function unquoteGitPath(input: string) { return new TextDecoder().decode(new Uint8Array(bytes)) } +export function decodeFilePath(input: string) { + try { + return decodeURIComponent(input) + } catch { + return input + } +} + +export function encodeFilePath(filepath: string): string { + return filepath + .split("/") + .map((segment) => encodeURIComponent(segment)) + .join("/") +} + export function createPathHelpers(scope: () => string) { const normalize = (input: string) => { const root = scope() const prefix = root.endsWith("/") ? root : root + "/" - let path = unquoteGitPath(stripQueryAndHash(stripFileProtocol(input))) + let path = unquoteGitPath(decodeFilePath(stripQueryAndHash(stripFileProtocol(input)))) if (path.startsWith(prefix)) { path = path.slice(prefix.length) @@ -100,7 +115,7 @@ export function createPathHelpers(scope: () => string) { const tab = (input: string) => { const path = normalize(input) - return `file://${path}` + return `file://${encodeFilePath(path)}` } const pathFromTab = (tabValue: string) => { |
