summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/components/prompt-input
diff options
context:
space:
mode:
authorKhang Ha (Kelvin) <[email protected]>2026-02-07 05:16:56 +0700
committerGitHub <[email protected]>2026-02-06 16:16:56 -0600
commitfde0b39b7c97dacb78cb55f3d963aa54f61650ea (patch)
tree066ebb3f0a2716c9e0ee8e72b55239ad249cd5d1 /packages/app/src/components/prompt-input
parente9a3cfc083bf480ba2c8aaa585a4e914549e3e56 (diff)
downloadopencode-fde0b39b7c97dacb78cb55f3d963aa54f61650ea.tar.gz
opencode-fde0b39b7c97dacb78cb55f3d963aa54f61650ea.zip
fix: properly encode file URLs with special characters (#12424)
Diffstat (limited to 'packages/app/src/components/prompt-input')
-rw-r--r--packages/app/src/components/prompt-input/build-request-parts.ts10
1 files changed, 8 insertions, 2 deletions
diff --git a/packages/app/src/components/prompt-input/build-request-parts.ts b/packages/app/src/components/prompt-input/build-request-parts.ts
index 4cf2f29ac..7010a1fd8 100644
--- a/packages/app/src/components/prompt-input/build-request-parts.ts
+++ b/packages/app/src/components/prompt-input/build-request-parts.ts
@@ -30,6 +30,12 @@ type BuildRequestPartsInput = {
const absolute = (directory: string, path: string) =>
path.startsWith("/") ? path : (directory + "/" + path).replace("//", "/")
+const encodeFilePath = (filepath: string): string =>
+ filepath
+ .split("/")
+ .map((segment) => encodeURIComponent(segment))
+ .join("/")
+
const fileQuery = (selection: FileSelection | undefined) =>
selection ? `?start=${selection.startLine}&end=${selection.endLine}` : ""
@@ -99,7 +105,7 @@ export function buildRequestParts(input: BuildRequestPartsInput) {
id: Identifier.ascending("part"),
type: "file",
mime: "text/plain",
- url: `file://${path}${fileQuery(attachment.selection)}`,
+ url: `file://${encodeFilePath(path)}${fileQuery(attachment.selection)}`,
filename: getFilename(attachment.path),
source: {
type: "file",
@@ -129,7 +135,7 @@ export function buildRequestParts(input: BuildRequestPartsInput) {
const used = new Set(files.map((part) => part.url))
const context = input.context.flatMap((item) => {
const path = absolute(input.sessionDirectory, item.path)
- const url = `file://${path}${fileQuery(item.selection)}`
+ const url = `file://${encodeFilePath(path)}${fileQuery(item.selection)}`
const comment = item.comment?.trim()
if (!comment && used.has(url)) return []
used.add(url)