datadog: fix UTF-8 continuation byte handling in metric name sanitiza…#212
Merged
kevinburkesegment merged 1 commit intomainfrom Nov 4, 2025
Merged
datadog: fix UTF-8 continuation byte handling in metric name sanitiza…#212kevinburkesegment merged 1 commit intomainfrom
kevinburkesegment merged 1 commit intomainfrom
Conversation
ecba2a6 to
9be582d
Compare
etiennep
previously approved these changes
Nov 4, 2025
…tion The previous implementation had a subtle bug when processing invalid UTF-8 sequences. When encountering an orphaned continuation byte (0x80-0xBF) or incomplete multi-byte sequence, the code would insert a replacement character but fail to skip the continuation bytes that followed. This could result in: 1. Invalid UTF-8 output when continuation bytes were processed as standalone characters 2. Multiple consecutive replacement characters instead of collapsing them 3. Incorrect handling of mixed valid/invalid UTF-8 sequences This fix properly skips continuation bytes after detecting invalid sequences, ensuring the output is always valid UTF-8. The change also renames `accentMap` to `latin1SupplementMap` with improved documentation to clarify that it maps Unicode codepoints in the Latin-1 Supplement range (U+00C0-U+00FF), not the array indices themselves. Added comprehensive test cases covering edge cases like orphaned continuation bytes, incomplete sequences, invalid surrogates, and mixed valid/invalid UTF-8. Also added fuzz testing and benchmarks to validate correctness and performance. Co-Authored-By: Claude <noreply@anthropic.com>
9be582d to
d6e7f85
Compare
etiennep
approved these changes
Nov 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…tion
The previous implementation had a subtle bug when processing invalid UTF-8 sequences. When encountering an orphaned continuation byte (0x80-0xBF) or incomplete multi-byte sequence, the code would insert a replacement character but fail to skip the continuation bytes that followed. This could result in:
This fix properly skips continuation bytes after detecting invalid sequences, ensuring the output is always valid UTF-8. The change also renames
accentMaptolatin1SupplementMapwith improved documentation to clarify that it maps Unicode codepoints in the Latin-1 Supplement range (U+00C0-U+00FF), not the array indices themselves.Added comprehensive test cases covering edge cases like orphaned continuation bytes, incomplete sequences, invalid surrogates, and mixed valid/invalid UTF-8. Also added fuzz testing and benchmarks to validate correctness and performance.