diff --git a/cmd/interactive.go b/cmd/interactive.go index 82a3bfcbe..702227116 100644 --- a/cmd/interactive.go +++ b/cmd/interactive.go @@ -531,6 +531,8 @@ func extractFileData(input string) (string, []api.ImageData, error) { return "", imgs, err } fmt.Fprintf(os.Stderr, "Added image '%s'\n", nfp) + input = strings.ReplaceAll(input, "'"+nfp+"'", "") + input = strings.ReplaceAll(input, "'"+fp+"'", "") input = strings.ReplaceAll(input, fp, "") imgs = append(imgs, data) } diff --git a/cmd/interactive_test.go b/cmd/interactive_test.go index 3f60448b6..ba8331918 100644 --- a/cmd/interactive_test.go +++ b/cmd/interactive_test.go @@ -1,6 +1,8 @@ package cmd import ( + "os" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -50,3 +52,24 @@ d:\path with\spaces\seven.JPEG inbetween7 c:\users\jdoe\eight.png inbetween8 assert.Contains(t, res[9], "ten.PNG") assert.Contains(t, res[9], "E:") } + +// Ensure that file paths wrapped in single quotes are removed with the quotes. +func TestExtractFileDataRemovesQuotedFilepath(t *testing.T) { + dir := t.TempDir() + fp := filepath.Join(dir, "img.jpg") + data := make([]byte, 600) + copy(data, []byte{ + 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 'J', 'F', 'I', 'F', + 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xd9, + }) + if err := os.WriteFile(fp, data, 0o600); err != nil { + t.Fatalf("failed to write test image: %v", err) + } + + input := "before '" + fp + "' after" + cleaned, imgs, err := extractFileData(input) + assert.NoError(t, err) + assert.Len(t, imgs, 1) + assert.Equal(t, cleaned, "before after") +}