stripControl is a defensive fallback used only if the sanitizing transform errors, which the asciisanitizer does not do in practice. It drops C0 control bytes other than tab, newline, and carriage return so the result can never carry an escape sequence.
(s string)
| 86 | // bytes other than tab, newline, and carriage return so the result can never |
| 87 | // carry an escape sequence. |
| 88 | func stripControl(s string) string { |
| 89 | return strings.Map(func(r rune) rune { |
| 90 | if r < 0x20 && r != '\t' && r != '\n' && r != '\r' { |
| 91 | return -1 |
| 92 | } |
| 93 | return r |
| 94 | }, s) |
| 95 | } |