Skip to content

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

@sc2ben

Description

@sc2ben

Summary

yamlNodeToJson in src/markdown/frontmatter.zig attempts numeric coercion on every YAML scalar, including scalars that were explicitly quoted as strings in the source. This means version: "1.1" (a quoted YAML string) comes back as .float = 1.1 instead of .string = "1.1".

Root cause

zig-yaml's Yaml.Value.scalar variant carries no quoting metadata — both 1.1 and "1.1" arrive as .scalar = "1.1". Without that information, yamlNodeToJson cannot distinguish them.

The current integer-first → float → string fallback order is correct (fixed in the previous commit from float-first), but quoted strings that happen to look like numbers will still be coerced.

Correct behaviour per YAML spec

A YAML double-quoted or single-quoted scalar is always a string, regardless of its content.

Fix options

  1. Short-term (done): reverse coercion order to int → float → string so bare integers stay integers.
  2. Long-term: upstream a zig-yaml patch to add a quoted_scalar: []const u8 variant (or a Style flag on .scalar) so zigmark can skip numeric coercion for quoted values.
  3. Alternative: switch to a YAML library that exposes scalar style, or write a thin wrapper that preserves quoting before handing off to Yaml.

Affected versions

Reproduced with zigmark path-dep on Zig 0.15.2; zig-yaml 0.2.0.

Example

version: "1.1"   # should be .string = "1.1"
weight: 10        # should be .integer = 10  (was .float before fix)
ratio: 1.5        # .float = 1.5  (correct — unquoted float)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions