public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH common] properly encode YAML via YAML::XS
@ 2020-09-17 11:16 Fabian Grünbichler
  2020-09-17 15:06 ` Thomas Lamprecht
  2020-09-18 12:36 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 2 replies; 5+ messages in thread
From: Fabian Grünbichler @ 2020-09-17 11:16 UTC (permalink / raw)
  To: pve-devel

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>
---

Notes:
    alternatives include:
    - dropping --output-format yaml altogether
    - manually recursively mapping JSON::true/false to some sensible value before dumping
    - outputting JSON instead of YAML, since the former is a subset of the latter (thanks Dominik ;))
    
    https://forum.proxmox.com/threads/yaml-issues-with-pvesh.76017/

 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.20.1





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-18 12:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 11:16 [pve-devel] [PATCH common] properly encode YAML via YAML::XS Fabian Grünbichler
2020-09-17 15:06 ` Thomas Lamprecht
2020-09-18  7:13   ` Fabian Grünbichler
2020-09-18 12:35     ` Thomas Lamprecht
2020-09-18 12:36 ` [pve-devel] applied: " Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal