Skip to content

Fix yaml numeric parsing#51

Merged
sc2ben merged 5 commits intomainfrom
50-yaml-scalar-parser-loses-quoting-information-quoted-numeric-strings-coerced-to-numbers
Apr 1, 2026
Merged

Fix yaml numeric parsing#51
sc2ben merged 5 commits intomainfrom
50-yaml-scalar-parser-loses-quoting-information-quoted-numeric-strings-coerced-to-numbers

Conversation

@sc2ben
Copy link
Copy Markdown
Contributor

@sc2ben sc2ben commented Apr 1, 2026

  • Update yamlNeedsQuote to quote strings that would be re-parsed as integers or floats (using inferValue)
  • Add empty scalar handling in .value case of treeNodeToJson (empty unquoted scalar → .null, restoring original behavior)
  • Add round-trip test for quoted numeric strings
  • Align inferValue with treeNodeToJson coercion: remove '.' dot-guard, always try parseFloat after parseInt fails (fixes scientific notation like 1e3)
  • Extend round-trip test to cover "1e3" (scientific notation)
  • Narrow inferValue docstring: "numeric coercion mirrors treeNodeToJson; bool/null handling is additional and not present in treeNodeToJson"
  • Code review passed

tsunaminoai
tsunaminoai previously approved these changes Apr 1, 2026
Copy link
Copy Markdown
Contributor

@tsunaminoai tsunaminoai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests pass.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Markdown frontmatter YAML parsing path to preserve quoted numeric scalars as strings (fixing #50) by converting from zig-yaml’s Tree nodes rather than the scalar Value API that loses quoting style.

Changes:

  • Switch YAML-to-JSON conversion to a Tree-node based walker that treats quoted scalars as strings and only coerces unquoted scalars to numbers.
  • Adjust YAML frontmatter memory management to use an arena for the generated std.json.Value tree.
  • Update/add tests to assert integer parsing (including negatives) and that quoted numeric strings remain strings.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/markdown/frontmatter.zig Reworks YAML conversion to use yaml.Tree nodes (with quoting awareness) and changes ownership/deinit strategy for YAML-derived JSON values.
src/markdown/frontmatter_test.zig Updates numeric expectations to .integer and adds a test ensuring quoted numeric scalars remain .string.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/markdown/frontmatter.zig
Comment thread src/markdown/frontmatter.zig Outdated
Comment thread src/markdown/frontmatter.zig
Comment thread src/markdown/frontmatter.zig
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
auto-merge was automatically disabled April 1, 2026 19:44

Head branch was pushed to by a user without write access

Copilot AI requested a review from tsunaminoai April 1, 2026 19:44
tsunaminoai
tsunaminoai previously approved these changes Apr 1, 2026
Copy link
Copy Markdown
Contributor

@tsunaminoai tsunaminoai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to my eyes

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/markdown/frontmatter.zig
… notation round-trip)

Agent-Logs-Url: https://github.com/sc2in/zigmark/sessions/2c047116-1248-491b-b7f9-fe0a79778218

Co-authored-by: tsunaminoai <3594035+tsunaminoai@users.noreply.github.com>
auto-merge was automatically disabled April 1, 2026 20:02

Head branch was pushed to by a user without write access

Copilot AI requested a review from tsunaminoai April 1, 2026 20:03
tsunaminoai
tsunaminoai previously approved these changes Apr 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/markdown/frontmatter.zig
Comment thread src/markdown/frontmatter_test.zig
… treeNodeToJson

Agent-Logs-Url: https://github.com/sc2in/zigmark/sessions/bec0d6f6-29c0-46e0-8496-a3fb365909f0

Co-authored-by: tsunaminoai <3594035+tsunaminoai@users.noreply.github.com>
auto-merge was automatically disabled April 1, 2026 20:18

Head branch was pushed to by a user without write access

Copilot AI requested a review from tsunaminoai April 1, 2026 20:19
@sc2ben sc2ben merged commit ff67b4b into main Apr 1, 2026
2 checks passed
@tsunaminoai tsunaminoai deleted the 50-yaml-scalar-parser-loses-quoting-information-quoted-numeric-strings-coerced-to-numbers branch April 1, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

YAML scalar parser loses quoting information: quoted numeric strings coerced to numbers

4 participants