From 2771db46ecdc1a8778ee336adde2399ccecc69c4 Mon Sep 17 00:00:00 2001 From: valoq Date: Fri, 12 Jun 2026 11:16:03 +0200 Subject: [PATCH] Fix: dont silently drop pasted files with newlines --- app.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index 1ee75766..725962b0 100644 --- a/app.go +++ b/app.go @@ -160,6 +160,13 @@ func loadFiles() (clipboard clipboard, err error) { } func saveFiles(clipboard clipboard) error { + for _, path := range clipboard.paths { + // the clipboard file stores one path per line so a newline cannot be saved + if strings.ContainsAny(path, "\n\r") { + return fmt.Errorf("cannot copy %s because the name contains a newline", path) + } + } + if err := os.MkdirAll(filepath.Dir(gFilesPath), 0o700); err != nil { return fmt.Errorf("creating data directory: %w", err) } @@ -183,10 +190,6 @@ func saveFiles(clipboard clipboard) error { } for _, path := range clipboard.paths { - if strings.ContainsAny(path, "\n\r") { - log.Printf("clipboard: skipping path with newline: %q", path) - continue - } if _, err := fmt.Fprintln(files, path); err != nil { return fmt.Errorf("write path to file: %w", err) }