From 585f3ad0be769e2ecaddb31c0f521cea9169915b Mon Sep 17 00:00:00 2001 From: Roo Code Date: Fri, 18 Jul 2025 16:43:23 +0000 Subject: [PATCH] fix: prevent double @ prefix in drag-and-drop file paths - Add early return in convertToMentionPath if path already starts with @ - Fixes issue where drag-and-drop paths like @/Logs/file.log would become @@/Logs/file.log - Add comprehensive tests for the new behavior - Resolves #5901 --- .../src/utils/__tests__/path-mentions.test.ts | 20 +++++++++++++++++++ webview-ui/src/utils/path-mentions.ts | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/webview-ui/src/utils/__tests__/path-mentions.test.ts b/webview-ui/src/utils/__tests__/path-mentions.test.ts index 1163324503..1512fbcadc 100644 --- a/webview-ui/src/utils/__tests__/path-mentions.test.ts +++ b/webview-ui/src/utils/__tests__/path-mentions.test.ts @@ -102,5 +102,25 @@ describe("Path Mentions Utilities", () => { const absPath = "/Users/test/project/src/file with spaces.ts" expect(convertToMentionPath(absPath, undefined)).toBe("/Users/test/project/src/file with spaces.ts") }) + + it("should return path as-is if it already starts with @", () => { + const mentionPath = "@/src/file.ts" + expect(convertToMentionPath(mentionPath, MOCK_CWD_POSIX)).toBe("@/src/file.ts") + }) + + it("should return path as-is if it already starts with @ even with spaces", () => { + const mentionPath = "@/src/file\\ with\\ spaces.ts" + expect(convertToMentionPath(mentionPath, MOCK_CWD_POSIX)).toBe("@/src/file\\ with\\ spaces.ts") + }) + + it("should return path as-is if it already starts with @ regardless of cwd", () => { + const mentionPath = "@/Logs/SCC_Engine_2025-07-18_18-29-42_0.log" + expect(convertToMentionPath(mentionPath, MOCK_CWD_POSIX)).toBe("@/Logs/SCC_Engine_2025-07-18_18-29-42_0.log") + }) + + it("should return path as-is if it already starts with @ even when cwd is undefined", () => { + const mentionPath = "@/some/path/file.txt" + expect(convertToMentionPath(mentionPath, undefined)).toBe("@/some/path/file.txt") + }) }) }) diff --git a/webview-ui/src/utils/path-mentions.ts b/webview-ui/src/utils/path-mentions.ts index 4ad25b9b56..70751d4684 100644 --- a/webview-ui/src/utils/path-mentions.ts +++ b/webview-ui/src/utils/path-mentions.ts @@ -23,6 +23,11 @@ export function escapeSpaces(path: string): string { * @returns A mention-friendly path */ export function convertToMentionPath(path: string, cwd?: string): string { + // If the path already starts with @, return it as-is to avoid double prefixing + if (path.startsWith("@")) { + return path + } + // Strip file:// or vscode-remote:// protocol if present let pathWithoutProtocol = path