all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH common v4 2/5] section config: prepare for supporting UTF-8 encoded configurations
Date: Tue, 10 Mar 2026 11:13:31 +0100	[thread overview]
Message-ID: <20260310101631.32870-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20260310101631.32870-1-f.ebner@proxmox.com>

Configurations registered as UTF-8 will be decoded after reading to
Perl's internal string format and thus may contain wide characters.
The Digest::SHA::sha1_hex() function croaks on wide characters, so
encode again before calling the function.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

Changes in v4:
* rather than searching for wide characters, tell parse_config()
  directly whether the file was registered as UTF-8

 src/PVE/SectionConfig.pm | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/PVE/SectionConfig.pm b/src/PVE/SectionConfig.pm
index 84ff81a..9ff91ee 100644
--- a/src/PVE/SectionConfig.pm
+++ b/src/PVE/SectionConfig.pm
@@ -103,6 +103,7 @@ use warnings;
 
 use Carp;
 use Digest::SHA;
+use Encode qw(encode);
 
 use PVE::Exception qw(raise_param_exc);
 use PVE::JSONSchema qw(get_standard_option);
@@ -1103,10 +1104,10 @@ sub get_property_schema {
 
 =head3 $base->parse_config(...)
 
-=head3 $base->parse_config($filename, $raw [, $allow_unknown ])
+=head3 $base->parse_config($filename, $raw [, $allow_unknown [, $options ]])
 
-    $config = PVE::Example::BasePlugin->parse_config($filename, $raw, $allow_unknown)
-    $config = $class->parse_config($filename, $raw, $allow_unknown)
+    $config = PVE::Example::BasePlugin->parse_config($filename, $raw, $allow_unknown, $options)
+    $config = $class->parse_config($filename, $raw, $allow_unknown, $options)
 
 Parses the contents of a file as C<L<PVE::SectionConfig>>, returning the parsed
 data annotated with additional information (see below).
@@ -1127,6 +1128,18 @@ The raw content of C<$filename>.
 
 Whether to allow parsing unknown I<types>.
 
+=item C<$options> (optional)
+
+Further options:
+
+=over
+
+=item C<$utf8>
+
+The config file was registered as UTF-8 encoded.
+
+=back
+
 =back
 
 The returned hash is structured as follows:
@@ -1205,7 +1218,7 @@ The error.
 =cut
 
 sub parse_config {
-    my ($class, $filename, $raw, $allow_unknown) = @_;
+    my ($class, $filename, $raw, $allow_unknown, $options) = @_;
 
     my $pdata = $class->private();
 
@@ -1214,7 +1227,13 @@ sub parse_config {
 
     $raw = '' if !defined($raw);
 
-    my $digest = Digest::SHA::sha1_hex($raw);
+    my $bytes = $raw;
+    if ($options && $options->{utf8}) {
+        # Digest::SHA croaks on wide characters
+        $bytes = encode('UTF-8', $raw);
+    }
+
+    my $digest = Digest::SHA::sha1_hex($bytes);
 
     my $pri = 1;
 
-- 
2.47.3





  parent reply	other threads:[~2026-03-10 10:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 10:13 [RFC common/cluster v4 0/5] cluster files: support registering UTF-8 configuration file Fiona Ebner
2026-03-10 10:13 ` [PATCH common v4 1/5] file: set contents: use strict UTF-8 encoding with $force_utf8 Fiona Ebner
2026-03-10 10:13 ` Fiona Ebner [this message]
2026-03-10 10:13 ` [PATCH cluster v4 3/5] cfs register file: avoid implicit return Fiona Ebner
2026-03-10 10:13 ` [PATCH cluster v4 4/5] d/control: add versioned breaks for libpve-access-control Fiona Ebner
2026-03-10 10:13 ` [PATCH cluster v4 5/5] cluster files: support registering UTF-8 configuration file Fiona Ebner
2026-03-10 10:40   ` Hannes Laimer
2026-03-10 11:01     ` Fiona Ebner
2026-03-10 11:47       ` Hannes Laimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260310101631.32870-3-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal