Skip to content

feat: implement folding for multiline plain and single-quoted scalars in deserialization#11

Merged
glucaci merged 1 commit intomainfrom
plain-scalar-deserialization
Jan 14, 2026
Merged

feat: implement folding for multiline plain and single-quoted scalars in deserialization#11
glucaci merged 1 commit intomainfrom
plain-scalar-deserialization

Conversation

@glucaci
Copy link
Member

@glucaci glucaci commented Jan 14, 2026

This pull request enhances the YAML deserialization logic to correctly handle folding of multiline plain and single-quoted scalars according to the YAML 1.2 specification. It introduces a new folding mechanism in the parser and adds comprehensive tests to ensure correct behavior for various multiline and quoted scalar scenarios.

Parser improvements:

  • Added logic in Utf8YamlReader.cs to fold line breaks into spaces for plain and single-quoted scalars, following YAML 1.2 folding rules. This includes a new FoldMultilineScalar method to handle folding and whitespace trimming, and updates to ensure single-quoted strings handle escaped quotes properly. [1] [2]
  • Improved double-quoted string decoding to handle both escape sequences and line breaks efficiently, optimizing the fast path for strings without escapes or line breaks.
  • Refined the folding logic for double-quoted strings to skip leading whitespace on continuation lines and correctly fold newlines into spaces.

Test coverage:

  • Added extensive tests in PrimitiveSerializationTests.cs to validate multiline scalar folding for plain, single-quoted, and double-quoted strings, including handling of blank lines, escaped quotes, long lines, and error cases such as invalid tab indentation.

These changes ensure the YAML parser now matches the expected YAML specification behavior for multiline scalar folding and improves robustness for edge cases.

@glucaci glucaci merged commit 248e513 into main Jan 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant