Skip to content

Stop skipping a comment at the end of input - #87

Open
AlbinoGeek wants to merge 2 commits into
andygrunwald:mainfrom
Rethunk-Tech:fix/comment-eof
Open

AlbinoGeek wants to merge 2 commits into
andygrunwald:mainfrom
Rethunk-Tech:fix/comment-eof

Conversation

@AlbinoGeek

Copy link
Copy Markdown

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.

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.
Copilot AI balanced review requested due to automatic review settings November 7, 2026 19:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread parser.go Outdated
Comment on lines 62 to 64
if tok == EOL || tok == EOF {
break
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, a NUL ends the scan but the recursive call kept reading. Comment skipping now returns EOF as is. 9b22cd5

Comment thread parser_test.go Outdated
Comment on lines +422 to +425
"\"a\" {\n// x\x00y\n",
} {
_, _ = NewParser(strings.NewReader(s)).Parse()
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

AlbinoGeek added a commit to Rethunk-Tech/vdf that referenced this pull request Nov 7, 2026
@AlbinoGeek

Copy link
Copy Markdown
Author

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.

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.

Parser hangs on a comment at end of input

2 participants