From 5e1a55db2dff4db46af2b587ec85b3a213bb7ad2 Mon Sep 17 00:00:00 2001 From: bhavesh Date: Sat, 18 Apr 2026 16:29:10 +0530 Subject: [PATCH] fix: strip surrounding quotes from drag-dropped file paths in interactive CLI --- cmd/interactive.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/interactive.go b/cmd/interactive.go index ea1ed9841..820151bbe 100644 --- a/cmd/interactive.go +++ b/cmd/interactive.go @@ -603,13 +603,20 @@ func normalizeFilePath(fp string) string { } func extractFileNames(input string) []string { - // Regex to match file paths starting with optional drive letter, / ./ \ or .\ and include escaped or unescaped spaces (\ or %20) - // and followed by more characters and a file extension - // This will capture non filename strings, but we'll check for file existence to remove mismatches - regexPattern := `(?:[a-zA-Z]:)?(?:\./|/|\\)[\S\\ ]+?\.(?i:jpg|jpeg|png|webp|wav)\b` + // Matches file paths that may be wrapped in single or double quotes (terminals often add these + // when dragging files with spaces), as well as unquoted paths with escaped or unescaped spaces. + // Quoted alternatives are listed first so the engine consumes the surrounding quotes and prevents + // a second match of the inner path by the unquoted alternative. + regexPattern := `(?:'(?:[a-zA-Z]:)?(?:\./|/|\\)[^']+?\.(?i:jpg|jpeg|png|webp|wav)'` + + `|"(?:[a-zA-Z]:)?(?:\./|/|\\)[^"]+?\.(?i:jpg|jpeg|png|webp|wav)"` + + `|(?:[a-zA-Z]:)?(?:\./|/|\\)[\S\\ ]+?\.(?i:jpg|jpeg|png|webp|wav)\b)` re := regexp.MustCompile(regexPattern) - return re.FindAllString(input, -1) + matches := re.FindAllString(input, -1) + for i, m := range matches { + matches[i] = strings.Trim(m, "\"'") + } + return matches } func extractFileData(input string) (string, []api.ImageData, error) { @@ -617,7 +624,7 @@ func extractFileData(input string) (string, []api.ImageData, error) { var imgs []api.ImageData for _, fp := range filePaths { - nfp := normalizeFilePath(fp) + nfp := normalizeFilePath(strings.Trim(fp, "\"'")) data, err := getImageData(nfp) if errors.Is(err, os.ErrNotExist) { continue @@ -633,6 +640,7 @@ func extractFileData(input string) (string, []api.ImageData, error) { fmt.Fprintf(os.Stderr, "Added image '%s'\n", nfp) } input = strings.ReplaceAll(input, "'"+nfp+"'", "") + input = strings.ReplaceAll(input, `"`+nfp+`"`, "") input = strings.ReplaceAll(input, "'"+fp+"'", "") input = strings.ReplaceAll(input, fp, "") imgs = append(imgs, data)