fix: sanitize names on file operations (#2546)

* fix: sanitize names on file operations

* dont strip internal colors

* minimize sanitation

* cover history entries

* minor improvement

* fix patch

* optimize patch
This commit is contained in:
valoq authored and GitHub committed 2026-05-19 11:27:02 +10:00
1 parent 42e567abbd
commit 0ca4d75b9b
3 files changed
+56 -20

No files matched your search

+25
View File
@@ -308,3 +308,28 @@ func sanitizeName(s string) string {
return '\uFFFD'
}, s)
}
// sanitizeMessage sanitizes a message intended for the message line. Like
// sanitizeName it strips control runes, but it preserves terminal sequences
// that lf itself recognizes (SGR, EL, OSC 8) so internal messages that use
// color or hyperlinks still render correctly.
func sanitizeMessage(s string) string {
s = strings.TrimRight(s, "\n\r")
var b strings.Builder
b.Grow(len(s))
for i := 0; i < len(s); {
if seq := readTermSequence(s[i:]); seq != "" {
b.WriteString(seq)
i += len(seq)
continue
}
r, w := utf8.DecodeRuneInString(s[i:])
if isControlChar(r) {
b.WriteRune('\uFFFD')
} else {
b.WriteRune(r)
}
i += w
}
return b.String()
}