fix(scanner): treat colon as plain scalar content in flow mapping keys#866
fix(scanner): treat colon as plain scalar content in flow mapping keys#866lawrence3699 wants to merge 1 commit intogoccy:masterfrom
Conversation
In flow mapping context, a ':' not followed by whitespace, a flow
indicator, or a quote should be part of the plain scalar key, not a
mapping value indicator. This fixes parsing of inputs like
{hello:world: [a,b,c]} where the key is the plain scalar 'hello:world'.
Fixes goccy#832
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #866 +/- ##
=======================================
Coverage 80.65% 80.66%
=======================================
Files 22 22
Lines 6845 6848 +3
=======================================
+ Hits 5521 5524 +3
Misses 905 905
Partials 419 419 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes flow-mapping key scanning so that : can be treated as plain-scalar content in unquoted keys when it is not followed by a “value-indicating” character sequence, resolving parsing failures like {hello:world: [a,b,c]} (Issue #832).
Changes:
- Updated
Scanner.scanMapDelim()to only treat:as a mapping value indicator in flow mappings when the next character makes the delimiter unambiguous (whitespace, flow indicators, collection starts, quotes, or EOS) and the current plain-scalar buffer is non-empty. - Added regression tests covering single/multiple colons in keys and nested flow structures.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| scanner/scanner.go | Refines : delimiter detection in flow mappings to allow unquoted keys like hello:world while keeping : a delimiter when unambiguous. |
| decode_test.go | Adds regression coverage for colon-containing unquoted keys in flow mappings, including nested flow collections. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fixes #832
Problem: Parsing
{hello:world: [a,b,c]}fails with',' or '}' must be specified, but this is valid YAML. The unquoted keyhello:worldis valid because the first:is not followed by whitespace. Without curly braces, parsing succeeds.Cause: In
scanMapDelim(), when inside a flow mapping (startedFlowMapNum > 0), almost every:was treated as a mapping value indicator. The only exception was:followed by/(for URLs). This meanthello:worldwas split at the first:.Fix: In flow mapping context, when scanning a plain scalar key (buffer is non-empty),
:is only treated as a mapping value indicator when followed by:,,},])[,{)",')When the buffer is empty (key was already tokenized, e.g. as a quoted string),
:remains a delimiter unconditionally. This subsumes the previous:/special case for URLs.Before:
{hello:world: [a,b,c]}→ errorAfter:
{hello:world: [a,b,c]}→map[hello:world:[a b c]]Validation: All existing tests pass, including the yaml-test-suite (355/402 = 88.3%, unchanged). Five regression tests added covering single and multiple colons in keys, mixed entries, and nested flow collections.