Skip to content

Quote strings that start or end with whitespace when writing YAML - #195

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/183-quote-trailing-whitespace
Oct 7, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/183-quote-trailing-whitespace

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #183

Before: a value ending in a tab was written as a plain scalar (k: tab<TAB>), and YAML strips trailing whitespace from plain scalars. So "tab\t" came back as "tab" and "x \t" as "x", through every writer, including a CombineFrontmatter rewrite of an already-quoted k: "tab\t".

After: these values round-trip unchanged. Ordinary values are still written plain.

How: the shared serializer in YamlSerializer.cs registers a ChainedEventEmitter that sets ScalarStyle.DoubleQuoted on any string whose first or last character is whitespace. WithQuotingNecessaryStrings stays in place for everything else.

Tests: new EdgeWhitespaceRoundTripTests covers leading and trailing tabs and spaces through AddFrontmatter/ExtractFrontmatter, a CombineFrontmatter rewrite of a quoted tab value, a direct SerializeYamlObject round trip, and a check that a plain value stays plain. Four of these fail without the change (trailing tab, trailing space then tab, the Combine rewrite, the serializer round trip) and all pass with it. Full suite: 273 passed. The library builds for netstandard2.0/2.1 and net8/9/10.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ho7QngpAmRRAxjmT2qp1sn


Generated by Claude Code

claude added 2 commits October 7, 2026 02:26
…tch]

WithQuotingNecessaryStrings leaves a string that ends in a tab as a plain
scalar, and YAML strips trailing whitespace from plain scalars, so "tab\t"
came back as "tab" after AddFrontmatter, ReplaceFrontmatter or a
CombineFrontmatter rewrite. A chained event emitter now double-quotes any
string whose first or last character is whitespace.

Fixes #183

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ho7QngpAmRRAxjmT2qp1sn
The build's ktsu.Sdk sync rewrote it, and it was committed by mistake.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ho7QngpAmRRAxjmT2qp1sn
@sonarqubecloud

sonarqubecloud Bot commented Oct 7, 2026

Copy link
Copy Markdown

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.

A string value ending in a tab is written as a plain scalar and loses the tab on the next read ("tab\t" round-trips to "tab")

2 participants