Repository navigation
fix(parser): quote encoded values the parser corrupts on reload - #106
Merged
Merged
Conversation
The encoder wrote values verbatim, but the parser trims surrounding whitespace, strips one matching quote pair, and reads a trailing backslash or triple-quote prefix as a multi-line marker. So WriteTo/Encode followed by LoadStrings/Parse silently dropped data from space-padded, surround-quoted and backslash-terminated values, and hard-errored on a trailing backslash. Wrap just the affected values in a non-colliding quote style the parser strips back off; values that already round-trip are emitted unchanged. Covers every encoder site: lite and full section k-v and array items, plus default-section k-v and arrays.
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.
WriteTo/Encodewrite values verbatim, but the parser trims surrounding whitespace, strips one matching quote pair, and treats a trailing\or a"""/'''prefix as a multi-line marker. Soparse(encode(x)) != xfor a whole class of ordinary values, and a trailing backslash aborts the entire load.The encoder now wraps only the values the parser would otherwise mangle (leading/trailing whitespace, matching surrounding quotes, trailing backslash, triple-quote prefix) in a quote style the existing parser strips back off, so no parser change is needed. Values that already round-trip are emitted byte-for-byte unchanged. Applied at every encoder site: lite and full section k-v and array items, plus default-section k-v and arrays.
Values containing a real newline still need a symmetric escape to round-trip (the parser only turns
\nback into a newline whenReplaceNlis set), so those are left as-is.Added round-trip tests for the affected value classes and a check that normal values are emitted unchanged.
go test ./...passes.