Skip to content

fix(yaml): correct scalar tag resolution, anchor binding, and flow entry validation - #7374

Open
arxhr007 wants to merge 1 commit into
denoland:mainfrom
arxhr007:fix/yaml-type-resolution
Open

arxhr007 wants to merge 1 commit into
denoland:mainfrom
arxhr007:fix/yaml-type-resolution

Conversation

@arxhr007

@arxhr007 arxhr007 commented Nov 3, 2026

Copy link
Copy Markdown

Summary

Differential testing of @std/yaml against js-yaml 4.1.0 (the library it is ported from) surfaced a family of scalar/tag-resolution divergences where @std/yaml threw on valid input, produced wrong values, or accepted invalid input:

  • !!int on decimal values threw Cannot resolve a node — the base-10 path of resolveYamlInteger ended in /^(:[0-5]?[0-9])+$/ tested against an empty slice (the base-60 :-break from js-yaml 3.x was dropped, and the pattern itself should have been zero-or-more). Explicit !!int 42 now resolves to 42; plain decimal resolution now return true per js-yaml.
  • 0o octal was unresolved — 0o17 parsed as the string "0o17". Added the 0o branch to both resolve and construct per js-yaml (0o17 → 15).
  • x: !!omap on an empty value threw TypeError: data is not iterable — resolveYamlOmap iterated null (raw TypeError leaked from parse()). Both resolve and construct now null-guard; an empty omap resolves to [] per js-yaml.
  • x: !!int on an empty value threw TypeError — resolveYamlInteger read data.length on null; added the data === null guard per js-yaml.
  • x: !!null on an empty value threw instead of resolving to null — added the data === null guard per js-yaml.
  • Anchors bound to the wrong node for indented scalars — a: &A\n value\nref: *A aliased to {} (or [] for an empty value) because resolveTag returned early on null/"!" tags without writing anchorMap[anchor] = result. Aliases now resolve to the composed scalar/null, matching js-yaml.
  • Empty flow-collection entries silently became null — [1, , 3] parsed as [1, null, 3]. Per YAML 1.2 §7.4 flow entries can never be empty; this now throws, matching js-yaml's expected the node content, but found ','.

Each divergence was verified to match js-yaml 4.1.0 behavior after the fix, including error-vs-ok parity on malformed input. Regression tests added to parse_test.ts covering all six cases.

Test plan

  • deno test yaml/ — 97 tests pass (6 new regression assertions/blocks)
  • deno lint yaml/ — clean
  • deno fmt --check yaml/ — clean

Known remaining divergences (out of scope, happy to follow up): @std/yaml is more lenient than js-yaml on indentation errors (e.g. tabs in indentation, keys abutting scalars) — a deliberate-looking strictness trade-off rather than a porting bug.

- resolveYamlInteger: the base-10 path always failed because the
  sexagesimal check ran on an empty slice; return true per js-yaml and
  handle null input. This also unbreaks explicit !!int tags on decimal
  values, which previously threw "Cannot resolve a node".
- resolveYamlInteger/constructYamlInteger: add the missing 0o octal
  form handled by js-yaml.
- resolveYamlOmap/construct: guard null input so an empty !!omap node
  resolves to [] instead of throwing "data is not iterable".
- nil: resolve null input so an empty !!null node resolves to null.
- resolveTag: bind the anchor for untagged/null-tag states so an
  anchor placed on a mapping key line aliases the indented scalar
  value instead of an empty container.
- readFlowCollections: reject empty entries per YAML 1.2 7.4 instead
  of silently pushing null.

All behaviors verified against js-yaml 4.1.0.
@CLAassistant

CLAassistant commented Nov 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the yaml label Nov 3, 2026
@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.03%. Comparing base (f834d02) to head (071c853).

Files with missing lines Patch % Lines
yaml/_type/int.ts 84.61% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7374      +/-   ##
==========================================
- Coverage   95.04%   95.03%   -0.02%     
==========================================
  Files         619      618       -1     
  Lines       52012    51778     -234     
  Branches     9450     9419      -31     
==========================================
- Hits        49434    49205     -229     
+ Misses       2031     2021      -10     
- Partials      547      552       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants