fix: filter newline (#2526)

This commit is contained in:
valoq authored and GitHub committed 2026-04-28 07:40:10 +02:00
1 parent ffe1ac1cb8
commit 54bcbca6ce
4 files changed
+39 -3

No files matched your search

+24 -3
View File
@@ -7,6 +7,7 @@ import (
"log"
"net"
"os"
"slices"
"strings"
"sync"
"time"
@@ -76,17 +77,30 @@ func run() {
}
if gPrintLastDir {
fmt.Println(app.nav.currDir().path)
dir := app.nav.currDir().path
if strings.ContainsAny(dir, "\n\r") {
log.Printf("last-dir: path contains newline: %q", dir)
} else {
fmt.Println(dir)
}
}
if gPrintSelection && len(app.selectionOut) > 0 {
for _, file := range app.selectionOut {
fmt.Println(file)
if strings.ContainsAny(file, "\n\r") {
log.Printf("selection: skipping path with newline: %q", file)
} else {
fmt.Println(file)
}
}
}
}
func writeLastDir(filename, lastDir string) {
if strings.ContainsAny(lastDir, "\n\r") {
log.Printf("last-dir: path contains newline: %q", lastDir)
return
}
f, err := os.Create(filename)
if err != nil {
log.Printf("opening last dir file: %s", err)
@@ -108,7 +122,14 @@ func writeSelection(filename string, selection []string) {
}
defer f.Close()
_, err = f.WriteString(strings.Join(selection, "\n"))
filtered := slices.DeleteFunc(slices.Clone(selection), func(s string) bool {
if strings.ContainsAny(s, "\n\r") {
log.Printf("selection: skipping path with newline: %q", s)
return true
}
return false
})
_, err = f.WriteString(strings.Join(filtered, "\n"))
if err != nil {
log.Printf("writing selection file: %s", err)
}