[pve-devel] [PATCH v10 storage 2/3] status: factoring out normalize_content_filename
Lorenz Stechauner
l.stechauner at proxmox.com
Tue Jun 22 11:19:21 CEST 2021
Signed-off-by: Lorenz Stechauner <l.stechauner at proxmox.com>
---
PVE/API2/Storage/Status.pm | 6 +-----
PVE/Storage.pm | 12 ++++++++++++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/PVE/API2/Storage/Status.pm b/PVE/API2/Storage/Status.pm
index 7069244..11ad60f 100644
--- a/PVE/API2/Storage/Status.pm
+++ b/PVE/API2/Storage/Status.pm
@@ -413,11 +413,7 @@ __PACKAGE__->register_method ({
my $size = -s $tmpfilename;
die "temporary file '$tmpfilename' does not exist\n" if !defined($size);
- my $filename = $param->{filename};
-
- chomp $filename;
- $filename =~ s/^.*[\/\\]//;
- $filename =~ s/[^-a-zA-Z0-9_.]/_/g;
+ my $filename = PVE::Storage::normalize_content_filename($param->{filename});
my $path;
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 519431c..20f1c3d 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1930,4 +1930,16 @@ sub assert_sid_unused {
return undef;
}
+# removes leading/trailing spaces and (back)slashes completely
+# substitutes every non-ASCII-alphanumerical char with '_', except '_.-'
+sub normalize_content_filename {
+ my ($filename) = @_;
+
+ chomp $filename;
+ $filename =~ s/^.*[\/\\]//;
+ $filename =~ s/[^a-zA-Z0-9_.-]/_/g;
+
+ return $filename;
+}
+
1;
--
2.30.2
More information about the pve-devel
mailing list