From 65dcc71f0e86642f512aeba9acc6b4c6068c01a0 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 12 Nov 2021 14:12:14 +0100 Subject: [PATCH] Bug 19318: Normalize uploaded file name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The uploaded file name can appear in the MARC record (if using the upload plugin), and all the strings in the MARC record are normalized using Unicode::Normalize::NFC. So the file name must be normalized everywhere (in the filesystem and in the uploaded_files table too). Test plan: 1. Create a file whose name contains combining characters. For instance: echo 'contents' > $(perl -e 'print "cine\x{cc}\x{81}ma"') 0xcc 0x81 is utf8 for "Combining acute accent" (́ ) https://unicode-table.com/fr/0301/ Once normalized it should be 0xc3 0xa9 (é) 2. Use the upload tool to upload this file 3. Verify on your filesystem that the filename is normalized % ls cin* | xxd 00000000: 6369 6ec3 a96d 610a cin..ma. ^^ ^^ 4. If you have configured the storage with a `baseurl`, use the upload cataloguing plugin, and verify that the generated URL works correctly Signed-off-by: Nick Clemens --- Koha/Uploader.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Koha/Uploader.pm b/Koha/Uploader.pm index 7ec04be8b8..799119c43d 100644 --- a/Koha/Uploader.pm +++ b/Koha/Uploader.pm @@ -67,6 +67,7 @@ use CGI; # no utf8 flag, since it may interfere with binary uploads use Digest::MD5; use Encode; use Time::HiRes; +use Unicode::Normalize; use base qw(Class::Accessor); @@ -249,6 +250,7 @@ sub _create_file { sub _hook { my ( $self, $filename, $buffer, $bytes_read, $data ) = @_; $filename= Encode::decode_utf8( $filename ); # UTF8 chars in filename + $filename = NFC($filename); $self->_compute( $filename, $buffer ); my $fh = $self->_fh( $filename ) // $self->_create_file( $filename ); print $fh $buffer if $fh; -- 2.30.2