Repository navigation
fix(kyaml): escape U+2028 and U+2029 so keys stay parseable by yq - #250
Conversation
go-yaml, the parser behind yq and standards' kyaml-format.sh, reads a
raw LS or PS as a line break (YAML 1.1 behaviour). In a key that makes
the document unparseable: `{"x<LS>y": 1}` written by `--output-format
kyaml` failed with "did not find expected ',' or '}'". NEL was already
escaped; LS and PS now are too, as `
` / `
`, which is valid
in YAML 1.1 and 1.2. serde-saphyr read the files correctly either way.
A new test covers NEL, LS and PS in keys; it fails on the previous
escape set with the raw separator in the output.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PFaqv6iBXrt3W5Akd1Fq5k
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Escape and validate Unicode separators src/kyaml.rs, CHANGELOG.adoc |
write_quoted escapes U+2028 and U+2029. The documentation and changelog describe the escape behaviour and parser handling. Tests cover value escaping and verify that keys containing NEL, U+2028 or U+2029 parse back to the original value. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related PRs
- hyperpolymath/panic-attack#234: Introduced
crate::yamlparsing and initial KYAML support.
Suggested reviewers: metadatastician
Merge Risk: 
Minimal · up to e914d
-
The change is mergeable with no identified current-head risk.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Follow-up to #248 (KYAML report output), found while drafting the upstream yq issue about its KYAML encoder.
Problem
go-yaml, the parser behind
yqand standards'scripts/kyaml-format.sh, treats a raw U+2028 (LS) or U+2029 (PS) as a line break, which is YAML 1.1 behaviour. Our emitter already escaped NEL (U+0085) but wrote LS and PS raw. A report key holding either one therefore produced KYAML thatyqcould not read at all:Values were unaffected, and
crate::yaml(serde-saphyr, YAML 1.2) read these files correctly before and after. In #248 I deliberately left U+2028 raw because YAML 1.2 calls it printable. Testing keys showed that was the wrong call for interop.Fix
write_quotedalso escapes U+2028 and U+2029 asand. Those escapes are valid in YAML 1.1 and 1.2, so nothing that parsed the old output loses anything.Validation
cargo fmt --check, pluscargo clippy --all-targets -D warningswith and without--all-features: clean.cargo test --all-features: all suites green (lib: 510 passed).line_breaks_in_keys_are_escapedcovers NEL, LS and PS in keys: exact output, and a round trip throughcrate::yaml. Run against the previous escape set, it fails with the raw separator in the output ("x\u{2028}y").escapes_non_printables_that_yq_writes_rawis updated: it asserted LS stays raw, and now asserts it is escaped.yqv4.54.1: KYAML from this branch with NEL, LS or PS in a key reads back intact (yq -p yaml -o json).One thing this PR can't fix
kyaml-format.sh --checkstill refuses these files:REFUSED — the KYAML rendering does not parse to the same data. The gate re-renders throughyq -o kyaml, and yq's encoder writes the characters raw again. That is the upstream yq bug:yqbuilt from my proposed upstream patch, the same three files pass (all 3 file(s) are KYAML).Until yq is fixed, a report key containing NEL, LS or PS can't pass the gate. Such keys are rare in practice, since report keys are field names and file paths.
Generated by Claude Code