fix(parse): require both closing brackets on an array-of-tables header - #66
Closed
MFA-G wants to merge 1 commit into
Closed
fix(parse): require both closing brackets on an array-of-tables header#66MFA-G wants to merge 1 commit into
MFA-G wants to merge 1 commit into
Conversation
The guard tested `ctx.p - 1`, the bracket `parseKey` had already
consumed, so it was always `]` and could never fire. The second bracket
was therefore never required and `ctx.p++` advanced past whatever
followed: `[[a]` parsed as `{a: [{}]}` at EOF, and `[[a]x` parsed the
same way with the `x` silently discarded.
Keep the old comparison (it rejects tokens between the two brackets,
since `parseKey` skips trailing whitespace) and add the check for the
second bracket at `ctx.p`. Fixes toml-test 1.1.0
`invalid/table/array-no-close-05` and `-06`; the four pre-existing
`array-no-close-01..04` cases all have a following line, so none
exercised the end-of-input path.
Member
|
AI garbage is not welcome here. And the fix isn't even done right but that's to be expected from a useless clanker. |
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.
Fixes #65.
Problem
An array-of-tables header closed by a single
]is accepted when it is the last thing in the document, and one trailing character is silently discarded:TOML 1.1.0 requires
array-table-close = ws %x5D.5D, so[[a]cannot derive fromarray-table. BurntSushi/toml, CPythontomlliband Rusttomlall reject it.Cause
ctx.p - 1is the]thatparseKeyhas already consumed, so the comparison is always true and the guard can never fire. The second bracket is never required, andctx.p++advances past whatever happens to be there. That accounts for the whole table: at EOF the increment is a no-op ([[a]), with exactly one trailing character it swallows it ([[a]x), and with more the leftovers produce an unrelated error ([[a]xyz).Fix
The old comparison is not dead weight —
parseKeycallsskipVoid(ctx, true, true)after the key, soctx.p - 1is what rejects tokens between the two brackets ([[uwu] ], covered by an existing test). The new condition keeps it and adds the missing requirement thatctx.pis the second bracket:charCodeAtpast the end returnsNaN, so EOF fails the check without a separate length test. The error pointer moves fromctx.p - 1(the consumed bracket) toctx.p(where the missing one should be).Validation
rejects invalid arrays of tablecovering[[uwu],[[uwu]x,[[uwu]and[[uwu]\nowo = 1.toml-test1.1.0 with the skips fromrun-toml-test.bash: 690 → 692 passing. The two newly passing cases areinvalid/table/array-no-close-05([[a]) and-06([[a]x), which landed in toml-test via Add invalid array-of-tables cases at end-of-input toml-lang/toml-test#205. The remaining failures (linetab-number-01..04,integer/long,utf8-bom-01/02) are pre-existing and untouched.[[a]],[[ a ]],[[a.b]],[[a]] # c,[[a]]\n[[a]], CRLF variants.Cost
One extra
charCodeAton the array-of-tables header path only — not on key-value lines, values, or plain[table]headers.