Skip to content

fix: reject content after table headers#5

Merged
dereuromark merged 1 commit intomasterfrom
fix/table-header-line-terminator
Mar 25, 2026
Merged

fix: reject content after table headers#5
dereuromark merged 1 commit intomasterfrom
fix/table-header-line-terminator

Conversation

@dereuromark
Copy link
Contributor

Summary

TOML spec requires table headers to be "on a line by themselves". The parser was incorrectly accepting invalid syntax like:

[table] key = "value"

This PR adds validation to reject content after table headers while still allowing valid comments:

[table] # this comment is valid
key = "value"

Changes

  • Add checkTableHeaderTerminator() method that validates table headers are followed only by newline, EOF, comment, or whitespace leading to those
  • Call the terminator check after successfully parsing table headers
  • Add tests for rejection and acceptance cases

Test Coverage

  • testDecodeRejectsContentAfterTableHeader - rejects [table] key = "value"
  • testDecodeRejectsContentAfterArrayTableHeader - rejects [[array]] key = "value"
  • testDecodeAcceptsCommentAfterTableHeader - accepts [table] # comment
  • testDecodeAcceptsWhitespaceBeforeCommentAfterTableHeader - accepts [table] # comment

TOML spec requires table headers to be "on a line by themselves".
This rejects invalid syntax like `[table] key = "value"` while
still allowing valid comments like `[table] # comment`.

Added checkTableHeaderTerminator() method that validates table
headers are followed only by newline, EOF, comment, or whitespace
leading to those.
@dereuromark dereuromark merged commit 4b45854 into master Mar 25, 2026
3 checks passed
@dereuromark dereuromark deleted the fix/table-header-line-terminator branch March 25, 2026 04:44
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