From: Michal Fox <me@dualfroz.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH common 2/2] cli formatter: decode the output of the yaml renderer
Date: Sun, 4 Oct 2026 14:32:02 +0000 [thread overview]
Message-ID: <20261004143202.7-3-me@dualfroz.com> (raw)
In-Reply-To: <20261004143202.7-1-me@dualfroz.com>
YAML::XS::Dump returns UTF-8 encoded octets, but the value returned by
a renderer gets encoded when the text output is printed, like any other
value. So for properties using the 'yaml' renderer, for example the
account details shown by 'pvenode acme account info', any non-ASCII
character got encoded twice and ended up mangled.
Decode the output of YAML::XS::Dump in the renderer, so it returns a
character string like all other renderers, and add a test for it.
Fixes: 99d0252 ("properly encode YAML via YAML::XS")
Signed-off-by: Michal Fox <me@dualfroz.com>
---
src/PVE/CLIFormatter.pm | 3 ++-
test/format_test.pl | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm
index d93bed6..758809e 100644
--- a/src/PVE/CLIFormatter.pm
+++ b/src/PVE/CLIFormatter.pm
@@ -27,7 +27,8 @@ PVE::JSONSchema::register_renderer('bytes', \&PVE::Format::render_bytes);
sub render_yaml {
my ($value) = @_;
- my $data = YAML::XS::Dump($value);
+ # YAML::XS returns UTF-8 encoded output, but renderers need to return text
+ my $data = decode('UTF-8', YAML::XS::Dump($value));
$data =~ s/^---[\n\s]//; # remove yaml marker
return $data;
diff --git a/test/format_test.pl b/test/format_test.pl
index 8ccfd5a..2b9460d 100755
--- a/test/format_test.pl
+++ b/test/format_test.pl
@@ -45,6 +45,7 @@ my $render_data = [
["bytes", 1024, undef, "1.00 KiB"],
["bytes", 1024 * 1024 * 123 + 1024 * 300, 1, "123.3 MiB"],
["bytes", 1024 * 1024 * 1024 * 1024 * 4 + 1024 * 1024 * 2048 * 8, undef, "4.02 TiB"],
+ ["yaml", { description => "Erkl\x{e4}rung" }, undef, "description: Erkl\x{e4}rung\n"],
];
foreach my $data (@$render_data) {
--
2.43.0
prev parent reply other threads:[~2026-10-04 14:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-04 14:32 [PATCH common 0/2] cli formatter: fix double UTF-8 encoding of YAML Michal Fox
2026-10-04 14:32 ` [PATCH common 1/2] fix #6305: cli formatter: avoid encoding YAML output twice Michal Fox
2026-10-04 14:32 ` Michal Fox [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261004143202.7-3-me@dualfroz.com \
--to=me@dualfroz.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox