From 99d02523f6f034760dd5e97e693a34b9ceb2a518 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabian=20Gr=C3=BCnbichler?= Date: Thu, 17 Sep 2020 13:16:58 +0200 Subject: [PATCH] properly encode YAML via YAML::XS MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit otherwise we get strange errors when formatting data that was originally JSON, and can thus contain JSON::true/JSON::false. one example is the QMP query-blockstats command, which gets called (and the resulting values returned) by /nodes/NODE/qemu/VMID/status/current Signed-off-by: Fabian Grünbichler --- debian/control | 1 + src/PVE/CLIFormatter.pm | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/debian/control b/debian/control index 4aa95ed..d7508f5 100644 --- a/debian/control +++ b/debian/control @@ -34,6 +34,7 @@ Depends: libclone-perl, libtimedate-perl, liburi-perl, libwww-perl, + libyaml-libyaml-perl, ${misc:Depends}, ${perl:Depends}, Breaks: ifupdown2 (<< 2.0.1-1+pve5), diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm index 4f18fa9..ccecfc3 100644 --- a/src/PVE/CLIFormatter.pm +++ b/src/PVE/CLIFormatter.pm @@ -5,7 +5,8 @@ use warnings; use I18N::Langinfo; use POSIX qw(strftime); -use CPAN::Meta::YAML; # comes with perl-modules +use YAML::XS; # supports Dumping JSON::PP::Boolean +$YAML::XS::Boolean = "JSON::PP"; use PVE::JSONSchema; use PVE::PTY; @@ -87,7 +88,7 @@ PVE::JSONSchema::register_renderer('bytes', \&render_bytes); sub render_yaml { my ($value) = @_; - my $data = CPAN::Meta::YAML::Dump($value); + my $data = YAML::XS::Dump($value); $data =~ s/^---[\n\s]//; # remove yaml marker return $data; @@ -440,7 +441,7 @@ sub print_api_result { } if ($format eq 'yaml') { - print encode('UTF-8', CPAN::Meta::YAML::Dump($data)); + print encode('UTF-8', YAML::XS::Dump($data)); } elsif ($format eq 'json') { # Note: we always use utf8 encoding for json format print to_json($data, {utf8 => 1, allow_nonref => 1, canonical => 1 }) . "\n"; -- 2.39.2