Skip to content

Fix parsing and writing bugs reported against v1 - #435

Merged
unknwon merged 3 commits into
mainfrom
v2-parse-fixes
Nov 11, 2026
Merged

unknwon merged 3 commits into
mainfrom
v2-parse-fixes

Conversation

@unknwon

@unknwon unknwon commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

Fixes seven bugs reported against v1 that v2 still had.

Default parsing changes:

With options:

Writing: a value with a backtick in the middle is no longer wrapped in """, unless it also has a comment symbol. #352.

#344 (multi-line JSON values) isn't fixed here: such a value can already be written in """ quotes.

The migration guide, README and package docs no longer say v2 parses every input exactly as v1, and list these fixes.

Link to the issue: #393, #328, #362, #390, #426, #205, #291, #352

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code.

Tests: lexer tests for each parsing fix, write round-trip cases for the footer, backtick quoting and an empty raw header after keys, new fuzz inputs, and a fuzz regression seed. go test -race ./..., lint and 1 minute of FuzzWriteRoundTrip pass.

AI usage

Written with Amp.

- Keep comment symbols inside a quoted value (issue 393, issue 328).
- Keep comment lines after the last key and write them back (issue 362).
- Skip a repeated byte order mark (issue 390).
- With SpaceBeforeInlineComment, start the comment at the first " #" or
  " ;" (issue 426).
- With AllowPythonMultilineValues, keep empty lines followed by an indented
  line (issue 205).
- Treat a raw section with an empty body as raw (issue 291).
- Don't wrap a value in """ for a backtick in the middle (issue 352).
- Add AllowBracketedValues to read a JSON-like value across lines
  (issue 344).
A value such as JSON can span lines in triple quotes, so the option isn't
needed. Its scan made parsing quadratic and skipped Python multiline
continuation.
A default section with keys followed by an empty [DEFAULT] header under
RawSections became raw, and Write then refused it. Also correct the
migration notes on write output, repeated byte order marks, Python
multiline values and where trailing comments are written.
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