bug: word-wrapping long values corrupts multi-byte UTF-8 characters #14
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
In
encoding/systemd/ast.go,AssignNode.String()(~lines 314–333), when a value's rendered line would exceed 80 columns, the wrap loop does:Ranging over a Go string yields byte offsets at each rune boundary, but
WriteByteonly copies the single byte at that offset — the remaining bytes of any multi-byte UTF-8 rune are silently dropped. Any long value containing non-ASCII characters (accented letters, non-Latin scripts, emoji, etc.) comes out corrupted after round-tripping through the AST'sString().Reproduction
produces mangled bytes such as
h�llo w�rldinstead of the original text, whenever the value is long enough to trigger the >80-column wrap path.Recommended fix
Iterate over the value by rune (e.g.
[]rune(valueText)or track byte ranges viautf8.DecodeRuneInString) and write whole runes (WriteRune/WriteString) instead of single bytes.