From 9a001dc7507e8e6ed13ad30572a2e269ee4abe2a Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 14 Mar 2025 06:00:26 +0000 Subject: [PATCH] Bug 39327: Add BOM to label CSV output and set output layer to UTF-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adds a BOM to the label CSV output, so that Excel properly recognizes the data as UTF-8. It also sets the output layer to UTF-8, so that Text::CSV_XS library always outputs UTF-8 even when it thinks a string might not be (see below) To reproduce: 1. Make a cataloguing record with the minimum requirements filled in 2. Set 100$a to Chödrön, Pema 3. Add an item with a barcode 4. Repeat this process but use 我爱你 for the 100$a 5. Create a new label batch 6. Add the item to the batch 7. Export using the defaults 8. click "Download as CSV" 9. Note that Chödrön appears correctly but the Chinese does not Test plan: 1. Apply the patch and koha-plack --restart kohadev 2. Do the "To reproduce" plan 3. Note that both Chödrön and 我爱你 appear correctly 4. If you were to inspect the bytes, you'd see that the output is UTF-8 encoded after the patch while Chödrön before the patch is Latin-1 encoded (ie ö when UTF-8 encoded is C3B6 and in Latin-1 it's encoded as F6) Signed-off-by: Phil Ringnalda --- labels/label-create-csv.pl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/labels/label-create-csv.pl b/labels/label-create-csv.pl index 1eeb42b685..1f0b4e770a 100755 --- a/labels/label-create-csv.pl +++ b/labels/label-create-csv.pl @@ -71,6 +71,10 @@ if (@label_ids) { my $csv = Text::CSV_XS->new( { formula => "empty" } ); +# Add BOM for UTF-8 encoded CSV +print "\xEF\xBB\xBF"; +binmode STDOUT, ':encoding(UTF-8)'; + foreach my $item (@$items) { my $label = C4::Labels::Label->new( batch_id => $batch_id, -- 2.48.1