[minor] Keep scalar types and nulls through a frontmatter round trip - #174
Merged
Merged
Conversation
Every scalar was read back as a string and written bare, so quoted "true", "1.0", "01234" and "null" came back as a bool, number or null, and an empty value became ''. The reader now keeps plain scalars typed (bool, integer, float, null) while quoted scalars stay strings, the writer quotes strings that would otherwise read as another type, and a null is kept as a null. PropertyMerger keeps a null-valued key instead of dropping it or throwing. ExtractFrontmatter now returns typed values for plain scalars rather than strings, hence [minor]. Fixes #137 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AFCuHRLN6NWMQ4DJNZApHa
…rip test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AFCuHRLN6NWMQ4DJNZApHa
…e tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AFCuHRLN6NWMQ4DJNZApHa
|
This was referenced Sep 30, 2026
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.



Fixes #137
What changed
This follows all three parts of the issue's suggested fix:
WithAttemptingUnquotedStringTypeDeserialization(). Plain scalars now come back as bool, integer, float or null, and quoted scalars stay strings.WithQuotingNecessaryStrings(), so a string such as"true"or"007"is written quoted. A realdraft: falseis still written as an unquoted boolean.ConvertValuekeeps a null as a null instead of turning it intostring.Empty.DefaultValuesHandling.Preservethen writes it back as a null.Keeping nulls needed a change in
PropertyMerger.MergePropertyGroup. It used to drop a group whose first value was null, and to throw when a mixed-type group contained a null. Both cases now copy every key through with its own value.Behaviour change
ExtractFrontmatter(and the other paths that read frontmatter) now return typed values for plain scalars, for examplebool, a number, ornull. Before, every scalar came back as a string. A caller that cast values tostringwill see different types, so this is tagged[minor].PropertyMergerTests.CombineFrontmatter_SingleBlockWithRepeatedListItems_RoundTripsTheListsasserted the old behaviour (scores: [1, 1, 2]read back as strings), so I updated it to compare numbers.Tests
Frontmatter.Test/ScalarTypeRoundTripTests.cs:CombineFrontmatterunderNoneandConservative. The output is re-read with a typed YamlDotNet reader. The quoted look-alikes stay strings,emptystays null,draftstays an unquotedfalse, andcountstays numeric.AddFrontmatterquotes"true"and"007".ExtractFrontmattertells a plainfalseapart from a quoted"false".Results:
dotnet test)YamlSerializer.csandPropertyMerger.csreverted: all 4 new tests fail🤖 Generated with Claude Code
https://claude.ai/code/session_01AFCuHRLN6NWMQ4DJNZApHa
Generated by Claude Code