properly encode YAML via YAML::XS

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 <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2020-09-17 13:16:58 +02:00 committed by Thomas Lamprecht
parent 09d47f9d47
commit 99d02523f6
2 changed files with 5 additions and 3 deletions

1
debian/control vendored
View File

@ -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),

View File

@ -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";