]> git.proxmox.com Git - pve-common.git/commitdiff
properly encode YAML via YAML::XS
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 17 Sep 2020 11:16:58 +0000 (13:16 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Sep 2020 11:40:55 +0000 (13:40 +0200)
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>
debian/control
src/PVE/CLIFormatter.pm

index 4aa95ed21fae1823e891e260b2fd883a14db9c3f..d7508f5bce8177f24ae2c69fcff1ab3ee99217fc 100644 (file)
@@ -34,6 +34,7 @@ Depends: libclone-perl,
          libtimedate-perl,
          liburi-perl,
          libwww-perl,
          libtimedate-perl,
          liburi-perl,
          libwww-perl,
+         libyaml-libyaml-perl,
          ${misc:Depends},
          ${perl:Depends},
 Breaks: ifupdown2 (<< 2.0.1-1+pve5),
          ${misc:Depends},
          ${perl:Depends},
 Breaks: ifupdown2 (<< 2.0.1-1+pve5),
index 4f18fa9e58d4f85d23a6b2637779f01652aa5772..ccecfc3af5fa90836670a50837bccc23014b22c6 100644 (file)
@@ -5,7 +5,8 @@ use warnings;
 
 use I18N::Langinfo;
 use POSIX qw(strftime);
 
 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;
 
 use PVE::JSONSchema;
 use PVE::PTY;
@@ -87,7 +88,7 @@ PVE::JSONSchema::register_renderer('bytes', \&render_bytes);
 sub render_yaml {
     my ($value) = @_;
 
 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;
     $data =~ s/^---[\n\s]//; # remove yaml marker
 
     return $data;
@@ -440,7 +441,7 @@ sub print_api_result {
     }
 
     if ($format eq 'yaml') {
     }
 
     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";
     } 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";