Repository navigation
Conversation
isPrintable has no branch for 4-byte UTF-8, so the emitter treats every character from U+10000 to U+10FFFF, emoji included, as non-printable: a plain scalar comes out double-quoted as "\U0001F916", and a literal or folded block scalar loses its style the same way. YAML 1.2's c-printable production (rule [1]) includes [#x10000-#x10FFFF], so no emoji detection is needed, only that range. It is opt-in to keep existing output byte-for-byte: WithSupplementaryUnicode() (or `supplementary-unicode: true` in OptsYAML) widens the emitter's check. isPrintable itself is unchanged, so parsing is unaffected. Refs yaml#354 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I'm unsure there is a need for an option, but maybe. We will discuss with other maintainers. We have already a PR for the issue But it was opened long time ago. We might go in one direction or another, so thank you for this PR I tend to say it shouldn't be an option as it's the expected behavior if we follow the YAML spec. But an option could be a good thing to ease migration. So maybe an option that is false for WithV2Defaults and WithV3Defaults, and true with WithV4Defaults |
|
@jtarchie could you check the other Unicode characters that were handled by |
yaml.v3 calls anything above U+FFFF unprintable, so fmt rewrote a `run: |` holding 🤖 as one double-quoted string, and when a `#` line followed it in the block, refused the file over a comment it thought it would lose (pipelines' work/linear-release.yml). v4 is the same by default; WithSupplementaryUnicode is the opt-in, in jtarchie/go-yaml until yaml/go-yaml#521 lands (go.mod replace). fmt's encoder sets WithLineWidth(-1): v4's v3 preset wraps at 80, which yaml.v3's encoder never did and would refold every long line. musttag is told v4's Marshal/Unmarshal, or the move would have dropped the check; five test calls on self-decoding types carry a nolint, since it knows only v3's Unmarshaler. extrahosts handles v4's new StreamNode kind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
We want to keep new options to a minimum. Each plugin we support comes with its own set of options, so I'd rather this fit into some kind of plugin category. We do want to generally be more in line with the spec, but not if it slows down processing or causes other pain. That said, almost any behavior you want to get should be available through some configuration of options and plugins. This one will need more planning by us. |
|
Closing because I didn't know about plugins. |
go-yaml's plugins hook loading only, so there is no emitter plugin to replace the fork's WithSupplementaryUnicode (yaml/go-yaml#521). fmt instead swaps each rune above U+FFFF for a private-use rune the file doesn't use, dumps, and swaps back in the text and the tree. Tests carry yaml/go-yaml#357's corpus through every place a pipeline holds text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
Adds an opt-in option,
WithSupplementaryUnicode(), that keeps emoji and other characters above U+FFFF as-is when writing YAML. Without it, nothing changes.Why
Today a string holding an emoji is written as
"\U0001F916", and a|block holding one is turned into a single quoted string. The YAML 1.2 spec counts these characters as printable, so tools that rewrite YAML files (formatters, config editors) end up making them harder to read. Refs #354.🤖 Generated with Claude Code