Repository navigation
Conversation
readKeyName moved past the delimiter by one byte, so a multi-byte delimiter such as ":" left its other bytes at the start of the value.
This branch has not been deployed
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.
Describe the pull request
With a non-ASCII key-value delimiter, the value keeps the delimiter's trailing bytes:
Same for a quoted key name (
"key 2"→value2gives"\x86\x92value2"). The value is not valid UTF-8 anymore.Cause:
readKeyNameinlexer.gofinds the delimiter withdelimiters.index, then returnsendIdx + 1as the value offset (both the plain and the quoted-name branch). That is one byte, but:is 3 bytes in UTF-8. The rest of the parser already handles non-ASCII delimiters and comment symbols (charSetfalls back tostrings.IndexAny, the writer usesstrings.ContainsAny), so only this offset was off. v1 has the same+ 1.Fix: move past the whole rune at the delimiter, using
utf8.DecodeRuneInString. ASCII delimiters are unchanged. I added a line about it to the parsing fixes indocs/migrate-v1-to-v2.md.Test: a new subtest in
Test_KeyValueDelimitersloadskey1:value1and"key 2"→value2withKeyValueDelimiters(":→"). It fails on main with the values above and passes with the change.go test -race -count=1 ./...,go vet ./...andgofmt -l .pass locally (Go 1.26.5, macOS arm64). I also ranFuzzWriteRoundTripfor 30s andFuzzStructMappingfor 20s with no failures. I did not run golangci-lint locally.Link to the issue: n/a
Checklist
AI usage
This PR was made with an AI coding agent (Claude): it found the bug while reading the lexer, wrote the fix and test, and ran the checks above. No human reviewed it before opening.