Repository navigation
Stop skipping a comment at the end of input - #87
AlbinoGeek wants to merge 2 commits into
Conversation
The skip looped until an EOL token, which never comes after a comment on the last line, or after a NUL byte (the scanner reads it as EOF). Fixes andygrunwald#86.
There was a problem hiding this comment.
🟡 Changes recommended
Comment scanning can resume after a NUL-triggered EOF and parse commented-out entries as active content, while the regression test fails to exercise that path.
2 open issues
What changed in this PR
This PR addresses #86 by updating the VDF parser’s comment-skipping loop to stop on EOF rather than wait indefinitely for a line ending.
Changes:
- Adds EOF as a termination condition when skipping comments.
- Adds regression cases for trailing comments and comments containing a NUL byte.
| File | Description |
|---|---|
parser.go |
Stops the comment-skipping loop on EOL or EOF. |
parser_test.go |
Adds parser termination tests for trailing and NUL-containing comments. |
Review effort: Balanced
| if tok == EOL || tok == EOF { | ||
| break | ||
| } |
There was a problem hiding this comment.
Right, a NUL ends the scan but the recursive call kept reading. Comment skipping now returns EOF as is. 9b22cd5
| "\"a\" {\n// x\x00y\n", | ||
| } { | ||
| _, _ = NewParser(strings.NewReader(s)).Parse() | ||
| } |
There was a problem hiding this comment.
Right, the old NUL sat inside an ident. The test now puts it after whitespace, with a quoted pair behind it, and asserts the map stays empty (fails on the old code). 9b22cd5
|
FYI: this fix is also maintained at https://github.com/Rethunk-Tech/vdf (module github.com/Rethunk-Tech/vdf/v2, v2.1.0 includes it, plus a Write function for #41). Leaving this PR open for you. |


The comment skip now also stops at EOF, so a comment on the last line or one holding a NUL byte no longer loops forever. Adds a regression test.
Fixes #86.