From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2FA1F62908 for ; Thu, 17 Sep 2020 13:17:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 19F61D40B for ; Thu, 17 Sep 2020 13:17:04 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 42EAED3F5 for ; Thu, 17 Sep 2020 13:17:03 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 0DC7C4540F for ; Thu, 17 Sep 2020 13:17:03 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Thu, 17 Sep 2020 13:16:58 +0200 Message-Id: <20200917111658.1358831-1-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.030 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [cliformatter.pm, proxmox.com] Subject: [pve-devel] [PATCH common] properly encode YAML via YAML::XS X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Sep 2020 11:17:34 -0000 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 --- 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