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
This commit is contained in:
Roo Code 2025-07-18 16:43:23 +00:00
parent a6e16e80d9
commit 585f3ad0be
2 changed files with 25 additions and 0 deletions

View file

@ -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")
})
})
})

View file

@ -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