Skip to content

Preserve string bytes when stripping ANSI colors - #112

Open
mikamikasuki wants to merge 1 commit into
lmittmann:mainfrom
mikamikasuki:fix/preserve-unicode-during-ansi-filtering
Open

mikamikasuki wants to merge 1 commit into
lmittmann:mainfrom
mikamikasuki:fix/preserve-unicode-during-ansi-filtering

Conversation

@mikamikasuki

Copy link
Copy Markdown

With NoColor enabled, a string attribute containing before�after currently renders as key=before. The ANSI filter stops at utf8.RuneError, including a valid U+FFFD character, and discards the rest of the text.

Continue filtering by rune, but retain the original byte spans. This preserves replacement characters and malformed UTF-8 bytes while allowing the existing quoting code to render them correctly.

Added nine cases for replacement characters, malformed and incomplete UTF-8, colored values, attribute keys, and plain text. Eight fail on the original code.

Validation: full CI-style race tests with faketime pass on Go 1.23 and 1.27; go vet and Staticcheck pass. A separate 325,185-case comparison with slog.TextHandler covers values, keys, ANSI filtering, cached attributes, and group names.

Prepared with AI assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant