You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An implicit mapping key longer than 1024 characters no longer loads. Before, there was no limit; now a document like this is rejected on every load path:
yamlrocks.loads(("k"*1025+": value\n").encode())
# before: {'kkk...': 'value'}# after: YAMLRocksParseError: an implicit mapping key cannot be longer than 1024 characters (write a longer key as an explicit '? ' key) at line 1, column 1
This is what the YAML spec requires, and PyYAML (C and pure Python) rejects the same documents. To adapt, write a longer key in the explicit form, which has no limit:
? kkkk...: value
dumps and the round-trip emitter now do that on their own. Nothing in the real-world corpus is affected.
Proposed change
YAML 1.2.2 (sections 7.4.2 and 8.2.2) limits an implicit key, the everyday key: value form, to a single line of at most 1024 characters. YAMLRocks had no limit, so a 1025 character plain key, a 2000 character quoted key and a long flow collection used as a key all loaded where PyYAML rejects them. Decided in the audit plan as a compliance fix.
The rule, as libyaml applies it:
The count is in characters, not bytes, from the key's first character (an anchor or tag in front of it included) up to the :, so spaces before the : count too.
It covers plain, single-quoted, double-quoted and flow collection keys, in block mappings, flow mappings and single pairs in flow sequences.
An explicit ? key has no limit, in block and in flow.
A short flow mapping key that spans lines ({ a\n : b }) still loads, as the spec and the YAML test suite require; only the length counts there.
The check lives in the scanner (MAX_IMPLICIT_KEY_CHARS in src/scanner/mod.rs). Every reader uses the one parser, so loads, OPT_ROUND_TRIP, OPT_ANNOTATED and !include give the same message, pointing at where the key starts. The verdict matches PyYAML's C and pure Python loaders on every boundary case checked (1024 against 1025 characters over 32 key shapes, including multibyte keys, properties, a BOM, comments and nested flow collections).
Emitters: a key that would come out longer than the limit is written in the explicit form, so output always loads back. Block: ? key then : value on the next line. Flow: {? key: v}. That holds for dumps, represent and the round-trip emitter, counted with one helper in src/emit_util.rs. A sweep of 12,960 dumps (nine key kinds, six value kinds, eight option sets, three widths, with and without represent) all reloaded to the same data, and libyaml loads the explicit output too. Unmodified documents re-emit byte for byte as before: any key that loaded is within the limit.
Speed: a pending key in the scanner is now dropped once it runs past the limit, so the tokens held back for it are released instead of waiting for the end of the line. On 1 MB of minified JSON, loads is about 1.25x faster with less than half the extra memory; round-trip about 1.08x. Pretty JSON, block documents and a minified value under a key are unchanged within noise.
Tests: new tests/core/test_long_keys.py (19 key shapes at the boundary on three load paths with exact messages and positions, !include, explicit keys of 5000 characters, dumps reloading across options, represent parity, round-trip re-emit), Rust boundary tests in the scanner (including one that the token queue stays bounded) and the encoder. Four existing fixtures used implicit keys over 1024 characters and now use the explicit form. The loading and dumping guides got a "Long keys" section.
Real-world corpus and YAML test suite: no file newly fails, and no pinned suite error message changed.
Type of change
Dependency or tooling upgrade
Bugfix (non-breaking change that fixes an issue)
New feature (non-breaking change that adds functionality)
Deprecation (replaces or removes a feature, with a migration path)
Breaking change (a fix or feature that changes existing behavior)
YAML 1.2.2 sections 7.4.2 and 8.2.2 limit an implicit key to one line of
at most 1024 characters. There was no limit at all, so keys PyYAML
rejects loaded here. The scanner now counts characters from the key's
first character, properties included, up to its `:`, as libyaml does,
for plain, quoted and flow collection keys. An explicit `? key` has no
limit.
Both emitters write a longer key in the explicit form, so their output
always loads back. A pending key that grows past the limit is dropped
early, which releases the tokens held for it: minified JSON loads about
1.25x faster.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: d4518613-bd29-462f-ba16-8b8665cda5d4
Commits
Reviewing files that changed from the base of the PR and between ca5f7f4 and aad8c8c.
Files selected for processing: 3
src/emit_util.rs
src/scanner/mod.rs
tests/core/test_long_keys.py
No actionable comments were generated in the recent review.
Walkthrough
The scanner now rejects implicit mapping keys longer than 1,024 characters and reports the key’s starting location. Explicit keys remain unlimited. Block and flow emitters use explicit-key syntax for over-limit keys. Tests and guides cover the limit, emitted form, and round-trip behavior.
Possibly related PRs
frenck/YAMLRocks#638: Updates scanner handling of mapping-key properties and round-trip emission of explicit keys, overlapping with the scanner and round-trip emitter changes here.
Merge Risk: Minimal · previous review ca5f7
The change adds a 1024-character limit for implicit mapping keys. Longer keys now fail to load unless written as explicit keys, and the emitters write them explicitly so their output still loads. This is documented, tests cover it, and no merge-blocking risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "Limit implicit keys to 1024 characters" names the main change: implicit mapping keys longer than 1024 characters are now limited and rejected on load, with explicit-key output on emit. The …
Description check
The description covers the behavior change, the YAML 1.2.2 basis, the emitter adjustments, the implementation location, tests, and the checklist. It is directly related to the changeset.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "Limit implicit keys to 1024 characters" names the main change: implicit mapping keys longer than 1024 characters are now limited and rejected on load, with explicit-key output on emit. The changeset (scanner check, emitters, tests, guides) matches this title.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: cb3c3106-fa4a-4e18-83da-c3f20e2f417f
Commits
Reviewing files that changed from the base of the PR and between 8d92f79 and ca5f7f4.
Files selected for processing: 3
docs/src/content/docs/guides/dumping.md
docs/src/content/docs/guides/loading.md
src/scanner/mod.rs
Files skipped from review as they are similar to previous changes: 2
docs/src/content/docs/guides/dumping.md
docs/src/content/docs/guides/loading.md
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.
285-286: Minor · Functional Correctness · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Clarify the round-trip form for flow keys.
An unmodified flow mapping such as {? <long key>: value} keeps its colon on the same line. The round-trip emitter preserves its bytes rather than moving the colon to the next line. Qualify the description for flow mappings.
As per coding guidelines, “an unmodified document must re-emit byte-for-byte.”
Source: Coding guidelines
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: b6d3498f-5609-40aa-adff-07e862185350
Commits
Reviewing files that changed from the base of the PR and between 2935faf and 8d92f79.
Files selected for processing: 10
docs/src/content/docs/guides/dumping.md
docs/src/content/docs/guides/loading.md
src/emit_util.rs
src/encode/mod.rs
src/key_text.rs
src/roundtrip/emit.rs
src/scanner/mod.rs
tests/core/test_long_keys.py
tests/features/test_options.py
tests/robustness/test_scaling.py
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
Opening a flow collection reset the explicit key flag and closing it
never put it back. A collection holding an open `?` entry, used as an
implicit key (`{{? long}: v}`), then skipped the length check. The flag
is now saved with the entry's key start and restored when the
collection closes.
The guides also say what the explicit form looks like in a flow
mapping.
On the docs note from the review (no inline thread, so answering here): fair, both guides described the explicit form as ": on the next line", which only holds in a block mapping. Since ca5f7f4 they spell out both forms: ? key with : value on the next line in a block mapping, {? key: value} in a flow mapping.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Implements YAML-spec compliance by enforcing a 1024-character maximum for implicit mapping keys during scanning, and updates emitters to automatically switch to explicit? key form when a key would exceed the limit.
Changes:
Add scanner enforcement for the 1024-character implicit-key limit (block + flow contexts) with consistent error reporting.
Update both the encoder emitter and round-trip emitter to emit overlong keys using explicit key syntax so output reloads successfully.
Add targeted regression tests and update docs/guides to document the limit and the explicit-key workaround.
File
Description
src/scanner/mod.rs
Enforces implicit-key length limit in the scanner; adds error construction and scanner boundary tests.
src/emit_util.rs
Adds shared helper to detect whether emitted key text exceeds the implicit-key character limit.
src/encode/mod.rs
Makes the encoder emitter write overlong keys using explicit ? key form (block + flow).
src/roundtrip/emit.rs
Makes the round-trip emitter switch to explicit keys when an inline key exceeds the implicit limit.
tests/core/test_long_keys.py
Adds comprehensive tests for boundary behavior across load paths and emitters.
tests/features/test_options.py
Updates duplicate-key error test fixture to avoid now-invalid overlong implicit keys.
tests/robustness/test_scaling.py
Updates scaling fixture to use explicit keys where needed under the new rule.
src/key_text.rs
Updates key-text rendering tests to use explicit keys for very long keys/collections.
docs/src/content/docs/guides/loading.md
Documents the implicit-key length limit and explicit-key workaround for loading.
docs/src/content/docs/guides/dumping.md
Documents that dumping emits long keys explicitly to preserve reloadability.
Both length checks only ask whether a key has more than 1024
characters, so they now stop there instead of counting the whole key.
Also fixes a doc comment that said the measured text includes the `:`,
and builds the test message from the limit.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.
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
bugfixInconsistencies or issues which will cause a problem for users or implementers.rust
2 participants
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.
Breaking change
An implicit mapping key longer than 1024 characters no longer loads. Before, there was no limit; now a document like this is rejected on every load path:
This is what the YAML spec requires, and PyYAML (C and pure Python) rejects the same documents. To adapt, write a longer key in the explicit form, which has no limit:
dumpsand the round-trip emitter now do that on their own. Nothing in the real-world corpus is affected.Proposed change
YAML 1.2.2 (sections 7.4.2 and 8.2.2) limits an implicit key, the everyday
key: valueform, to a single line of at most 1024 characters. YAMLRocks had no limit, so a 1025 character plain key, a 2000 character quoted key and a long flow collection used as a key all loaded where PyYAML rejects them. Decided in the audit plan as a compliance fix.The rule, as libyaml applies it:
:, so spaces before the:count too.? keyhas no limit, in block and in flow.{ a\n : b }) still loads, as the spec and the YAML test suite require; only the length counts there.The check lives in the scanner (
MAX_IMPLICIT_KEY_CHARSinsrc/scanner/mod.rs). Every reader uses the one parser, soloads,OPT_ROUND_TRIP,OPT_ANNOTATEDand!includegive the same message, pointing at where the key starts. The verdict matches PyYAML's C and pure Python loaders on every boundary case checked (1024 against 1025 characters over 32 key shapes, including multibyte keys, properties, a BOM, comments and nested flow collections).Emitters: a key that would come out longer than the limit is written in the explicit form, so output always loads back. Block:
? keythen: valueon the next line. Flow:{? key: v}. That holds fordumps,representand the round-trip emitter, counted with one helper insrc/emit_util.rs. A sweep of 12,960 dumps (nine key kinds, six value kinds, eight option sets, three widths, with and withoutrepresent) all reloaded to the same data, and libyaml loads the explicit output too. Unmodified documents re-emit byte for byte as before: any key that loaded is within the limit.Speed: a pending key in the scanner is now dropped once it runs past the limit, so the tokens held back for it are released instead of waiting for the end of the line. On 1 MB of minified JSON,
loadsis about 1.25x faster with less than half the extra memory; round-trip about 1.08x. Pretty JSON, block documents and a minified value under a key are unchanged within noise.Tests: new
tests/core/test_long_keys.py(19 key shapes at the boundary on three load paths with exact messages and positions,!include, explicit keys of 5000 characters, dumps reloading across options,representparity, round-trip re-emit), Rust boundary tests in the scanner (including one that the token queue stays bounded) and the encoder. Four existing fixtures used implicit keys over 1024 characters and now use the explicit form. The loading and dumping guides got a "Long keys" section.Real-world corpus and YAML test suite: no file newly fails, and no pinned suite error message changed.
Type of change
Additional information
Checklist
uv run pytestpasses locally. A pull request cannot be merged unless CI is green.uv run ruff check .anduv run ruff format --check .pass.cargo fmt --checkandcargo clippy --all-targets -- -D warningspass.If the change is user-facing:
docs/is added or updated, anddocs/verify_examples.pystill passes.