yaml: pure-Lua parser not round-trip safe for quoted strings #60

Closed
opened 2026-10-02 20:04:35 +02:00 by michael · 0 comments
Owner

Problem

The pure-Lua YAML backend is not round-trip safe with its own dump.
yaml.dump escapes " as \", but yaml/parse.lua does not
interpret escape sequences in quoted strings (documented in
docs/yaml.md). A value written by the library comes back altered.

The lyaml backend does interpret escapes, so the same YAML file
yields different data depending on which backend is installed.

Reproduce (v2.1.1, backend pure-lua)

local y = require("daw.common.yaml")
local t = y.load(y.dump({ a = 'say "hi"' }))
print(t.a)   -- prints: say \"hi\"   expected: say "hi"

Also: 'it''s' loads as it''s (expected: it's).

Why it matters

Planned contract daw_inventory/v1 uses YAML as exchange format
between a POSIX-sh collector and Lua reports. System values
(cron lines, service descriptions, kernel parameters) contain
quotes and backslashes. Results must not depend on the backend.

Acceptance criteria

  • parse.lua resolves " and \ inside double-quoted scalars
  • parse.lua resolves '' inside single-quoted scalars
  • Round-trip test dump -> load in test/test_yaml.lua for:
    say "hi", a\b, x # y, k: v, it's
  • Same results for pure-lua and lyaml backend
  • docs/yaml.md parser scope updated
## Problem The pure-Lua YAML backend is not round-trip safe with its own dump. `yaml.dump` escapes `"` as `\"`, but `yaml/parse.lua` does not interpret escape sequences in quoted strings (documented in docs/yaml.md). A value written by the library comes back altered. The lyaml backend does interpret escapes, so the same YAML file yields different data depending on which backend is installed. ## Reproduce (v2.1.1, backend pure-lua) local y = require("daw.common.yaml") local t = y.load(y.dump({ a = 'say "hi"' })) print(t.a) -- prints: say \"hi\" expected: say "hi" Also: 'it''s' loads as it''s (expected: it's). ## Why it matters Planned contract daw_inventory/v1 uses YAML as exchange format between a POSIX-sh collector and Lua reports. System values (cron lines, service descriptions, kernel parameters) contain quotes and backslashes. Results must not depend on the backend. ## Acceptance criteria - [ ] parse.lua resolves \" and \\ inside double-quoted scalars - [ ] parse.lua resolves '' inside single-quoted scalars - [ ] Round-trip test dump -> load in test/test_yaml.lua for: say "hi", a\b, x # y, k: v, it's - [ ] Same results for pure-lua and lyaml backend - [ ] docs/yaml.md parser scope updated
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/daw-lua-common#60
No description provided.