preview returns a short, escape-stripped excerpt of an input line for safe logging. We never want to dump full user input to the log.
(s string)
| 155 | // preview returns a short, escape-stripped excerpt of an input line for |
| 156 | // safe logging. We never want to dump full user input to the log. |
| 157 | func preview(s string) string { |
| 158 | const maxLen = 24 |
| 159 | out := make([]rune, 0, maxLen) |
| 160 | for _, r := range s { |
| 161 | if r < 0x20 || r == 0x7f { |
| 162 | continue |
| 163 | } |
| 164 | out = append(out, r) |
| 165 | if len(out) >= maxLen { |
| 166 | out = append(out, '…') |
| 167 | break |
| 168 | } |
| 169 | } |
| 170 | return string(out) |
| 171 | } |