Просмотр исходного кода

fix: encode & decode file paths (#843)

Aiden Cline 7 месяцев назад
Родитель
Сommit
8b2a909e1f
2 измененных файлов с 6 добавлено и 3 удалено
  1. 4 2
      packages/opencode/src/session/index.ts
  2. 2 1
      packages/tui/internal/components/chat/editor.go

+ 4 - 2
packages/opencode/src/session/index.ts

@@ -350,7 +350,9 @@ export namespace Session {
           switch (url.protocol) {
           switch (url.protocol) {
             case "file:":
             case "file:":
               // have to normalize, symbol search returns absolute paths
               // have to normalize, symbol search returns absolute paths
-              const relativePath = url.pathname.replace(app.path.cwd, ".")
+              // Decode the pathname since URL constructor doesn't automatically decode it
+              const pathname = decodeURIComponent(url.pathname)
+              const relativePath = pathname.replace(app.path.cwd, ".")
               const filePath = path.join(app.path.cwd, relativePath)
               const filePath = path.join(app.path.cwd, relativePath)
 
 
               if (part.mime === "text/plain") {
               if (part.mime === "text/plain") {
@@ -414,7 +416,7 @@ export namespace Session {
               return [
               return [
                 {
                 {
                   type: "text",
                   type: "text",
-                  text: `Called the Read tool with the following input: {\"filePath\":\"${url.pathname}\"}`,
+                  text: `Called the Read tool with the following input: {\"filePath\":\"${pathname}\"}`,
                   synthetic: true,
                   synthetic: true,
                 },
                 },
                 {
                 {

+ 2 - 1
packages/tui/internal/components/chat/editor.go

@@ -4,6 +4,7 @@ import (
 	"encoding/base64"
 	"encoding/base64"
 	"fmt"
 	"fmt"
 	"log/slog"
 	"log/slog"
+	"net/url"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
 	"strconv"
 	"strconv"
@@ -180,7 +181,7 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 			attachment := &textarea.Attachment{
 			attachment := &textarea.Attachment{
 				ID:        uuid.NewString(),
 				ID:        uuid.NewString(),
 				Display:   "@" + filePath,
 				Display:   "@" + filePath,
-				URL:       fmt.Sprintf("file://./%s", filePath),
+				URL:       fmt.Sprintf("file://./%s", url.PathEscape(filePath)),
 				Filename:  filePath,
 				Filename:  filePath,
 				MediaType: mediaType,
 				MediaType: mediaType,
 			}
 			}