fix: reject out-of-order concrete+super table redefinitions at parse time#530
Open
gaoflow wants to merge 1 commit into
Open
fix: reject out-of-order concrete+super table redefinitions at parse time#530gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
…time Out-of-order value-vs-table and dotted-key-vs-table redefinitions were silently accepted (or only raised on access) because the inner if-elif chain in Container.append had no else clause for the case where an existing concrete table is extended by a super-table after an unrelated table header. - Add else clause that validates the super-table against the concrete table, catching type mismatches and double table definitions at parse time instead of lazily during access/unwrap. - Enhance _validate_table_candidate to detect when a non-dotted candidate key is a prefix of an existing dotted key. - Call _validate_out_of_order_table after _raw_append in the fallthrough path so out-of-order fragments are validated before the document is materialized. Fixes python-poetry#523
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.
Out-of-order value-vs-table and dotted-key-vs-table redefinitions
were silently accepted (or only raised on access) because the inner
if-elif chain in
Container.appendhad noelseclause for the casewhere an existing concrete table is extended by a super-table after
an unrelated table header.
Changes
elseclause inContainer.appendthat validates the super-tableagainst the concrete table, catching type mismatches and double table
definitions at parse time instead of lazily during access/unwrap.
_validate_table_candidateto detect when a non-dottedcandidate key is a prefix of an existing dotted key.
_validate_out_of_order_tableafter_raw_appendin thefallthrough path so out-of-order fragments are validated immediately
(previously this validation only ran in the super+super INSERT path).
Scenarios fixed
Value-then-table split —
[a]\nb = true\n[zz]\nq = 9\n[a.b]\nc = 1\n(out-of-order) now raises
ParseErrorat parse time.Dotted-key-then-table split —
[a]\nb.c = 1\n[zz]\nq = 9\n[a.b]\nd = 2\n(out-of-order) now raises
ParseErrorat parse time.Dotted prefix (in-order) —
[a]\nb.c=1\n[a.b]\nd=2\nnow raisesTOMLKitErrorat parse time.Valid out-of-order tables (e.g.
[a]\nx=1\n[zz]\n[a.b]\nc=1\n) continueto parse and round-trip correctly.
Fixes #523