fix: quote flow scalars where a colon precedes a flow indicator - #773
Merged
Merged
Conversation
abdulhafeezenayatallh-lang
approved these changes
Jul 16, 2026
10 tasks
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.
Problem
Flow-style dump produces output the library cannot re-parse when a plain scalar contains a
:immediately followed by a flow indicator ({ } [ ] ,):This breaks
load(dump(x))for values such as':{',':[',':,',':}',':]', and'x:{', in both flow sequences and flow mappings. Block style is unaffected — there the scalar stays plain and round-trips fine, which is correct.Root cause
isPlainSafeinsrc/ast/presenter.tsdecides whether a character may appear unescaped in a plain scalar. Its last clause implements the spec'sns-plain-charrule for a:followed by content:The clause was
(prev === CHAR_COLON && cIsNsChar), i.e. it treated any ns-char after a colon as safe. Butns-plain-safe(c)is context-dependent:ns-plain-safe-out ::= ns-char(block context)ns-plain-safe-in ::= ns-char - c-flow-indicator(flow context)In flow context the following character must additionally not be a flow indicator. Because the clause skipped that exclusion,
{ } [ ] ,after a:were wrongly accepted, so the scalar was emitted plain and the{/[/,reopened or closed the surrounding flow collection.Fix
Add the
c-flow-indicatorexclusion to the colon clause when not in block context, matchingns-plain-safe-in. The#-after-colon case (:#) and normal:xstay plain; flow indicators after a colon now force quoting.Verification
Added
flowLevel — quotes a colon followed by a flow indicatortotest/core/units/dump-options.test.mjs, assertingload(dump(value, { flowLevel: 0 })) === valuefor the affected strings in flow sequences and mappings.missed comma between flow collection entries.npm test, 1599 passing, 0 failing). No over-quoting —:a,a:b,:#,http://xremain plain in flow.dist/is gitignored, so no build artifacts are committed.