fix: don't silently drop pasted files with newlines (#2620)
This commit is contained in:
1 parent
4e4701addd
commit
230ef16ea3
1 file changed
+7
-4
@@ -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)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user