From c517652a0a9df27f209a593932bc48f27679af4a Mon Sep 17 00:00:00 2001 From: plk Date: Sun, 14 Apr 2024 16:07:39 +0200 Subject: [PATCH] Looking at #474 --- bin/biber | 9 +++++++++ lib/Biber/Config.pm | 9 ++++++--- lib/Biber/Constants.pm | 1 + lib/Biber/Output/base.pm | 10 ++++++++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bin/biber b/bin/biber index fbcc1603a..ebd6098bd 100755 --- a/bin/biber +++ b/bin/biber @@ -20,6 +20,7 @@ use Encode; use File::Spec; use Pod::Usage; use List::AllUtils qw( first ); +use Unicode::Normalize qw(NFC); use Getopt::Long qw/:config no_ignore_case/; my $opts = {}; @@ -341,6 +342,14 @@ $logfile->info("=== $time_string"); my $bcf = Biber::Config->getoption('bcf'); +# Determine the input Unicode form so we can make sure output filenames are the +# same format +if ($bcf eq NFC($bcf)) { + Biber::Config->setoption('UFORM', 'NFC'); +} else { + Biber::Config->setoption('UFORM', 'NFD'); +} + if (Biber::Config->getoption('output_file')) { $outfile = Biber::Config->getoption('output_file') } diff --git a/lib/Biber/Config.pm b/lib/Biber/Config.pm index e99fe1be9..d8c98e89c 100644 --- a/lib/Biber/Config.pm +++ b/lib/Biber/Config.pm @@ -18,7 +18,7 @@ use Log::Log4perl::Appender::Screen; use Log::Log4perl::Appender::File; use Log::Log4perl::Layout::SimpleLayout; use Log::Log4perl::Layout::PatternLayout; -use Unicode::Normalize; +use Unicode::Normalize qw(normalize NFC NFD); use parent qw(Class::Accessor); __PACKAGE__->follow_best_practice; @@ -224,8 +224,11 @@ sub _initopts { } } - # Sanitse log file name to NFC - $biberlog = NFC($biberlog); + # Sanitise log file name to the same as the input .bcf + if ($biberlog) { + $biberlog = normalize('NFD', $biberlog); + # $biberlog = normalize(Biber::Config->getoption('UFORM'), $biberlog); + } # cache meta markers since they are referenced in the oft-called _get_handler $CONFIG_META_MARKERS{annotation} = quotemeta(Biber::Config->getoption('annotation_marker')); diff --git a/lib/Biber/Constants.pm b/lib/Biber/Constants.pm index ef4dafc55..6dad80a24 100644 --- a/lib/Biber/Constants.pm +++ b/lib/Biber/Constants.pm @@ -311,6 +311,7 @@ our $CONFIG_DEFAULT_BIBER = { xdatasep => { content => '-' }, xnamesep => { content => '=' }, xsvsep => { content => q/\s*,\s*/ }, + UFORM => { content => 'NFC' } }; # Set up some re-usable CSV parsers here for efficiency reasons diff --git a/lib/Biber/Output/base.pm b/lib/Biber/Output/base.pm index 7b03b150a..989ab95b3 100644 --- a/lib/Biber/Output/base.pm +++ b/lib/Biber/Output/base.pm @@ -10,7 +10,7 @@ use IO::File; use Text::Wrap; $Text::Wrap::columns = 80; use Log::Log4perl qw( :no_extra_logdie_message ); -use Unicode::Normalize; +use Unicode::Normalize qw(normalize NFC NFD); my $logger = Log::Log4perl::get_logger('main'); =encoding utf-8 @@ -60,7 +60,13 @@ sub set_output_target_file { if (my $enc = Biber::Config->getoption('output_encoding')) { $enc_out = ":encoding($enc)"; } - return IO::File->new($file, ">$enc_out"); + + if (ref($file) eq 'SCALAR') { + return IO::File->new($file, ">$enc_out"); + } + else { + return IO::File->new(normalize(Biber::Config->getoption('UFORM'), $file), ">$enc_out"); + } } =head2 get_output_target_file