Skip to content
Myr

Strip UTF-8-encoded C1 control characters from rendered items

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The display sanitizer already stripped raw 8-bit C1 bytes (0x80-0x9F) because they decode to RuneError as standalone bytes. Their valid UTF-8 encodings (0xC2 0x80 .. 0xC2 0x9F) decode to the same code points but were passed through, allowing a filename or input line containing CSI (U+009B), OSC (U+009D), or DCS (U+0090) to inject terminal control sequences when rendered.

authored by Junegunn Choi · committed by Junegunn Choi · parent b4a86a9 · Browse files · 1 file+2 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−1 removed

  • other:+2 added−1 removed

1 file+2 added−1 removed

modified:src/tui/light.go+2 added-1 removed
65 unmodified lines
66 runes := []rune{}67 for len(bytes) > 0 {68 r, sz := utf8.DecodeRune(bytes)69 nlcr := r == '\n' || r == '\r'70 isC1 := r >= 0x80 && r <= 0x9F70 if r >= 32 || r == '\x1b' || nlcr {71 if (r >= 32 && !isC1) || r == '\x1b' || nlcr {72 if nlcr && !allowNLCR {73 if r == '\r' {74 runes = append(runes, []rune(CR+resetCode)...)75 } else {
1487 unmodified lines