Skip to content

Commit

Permalink
Item13405: Fix normalization of filenames on NFD filesystems
Browse files Browse the repository at this point in the history
  • Loading branch information
gac410 committed Dec 23, 2015
1 parent f645de4 commit 571a359
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
12 changes: 11 additions & 1 deletion RCSStoreContrib/lib/Foswiki/Store/Rcs/Store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ our @ISA = ('Foswiki::Store');

use Assert;
use Error qw( :try );
use Encode;

use Foswiki ();
use Foswiki::Meta ();
Expand Down Expand Up @@ -113,7 +114,16 @@ sub readTopic {

( my $text, $isLatest ) = $handler->getRevision($version);
$text = '' unless defined $text;
$text = _decode($text);

# Use Encode::decode directly. Don't NFC normalize the topic text.
# Only need to normalize filenames.
$text = Encode::decode(
$Foswiki::cfg{Store}{Encoding} || 'utf-8',
$text,

#Encode::FB_CROAK # DEBUG
Encode::FB_PERLQQ
);
$text =~ s/\r//g; # Remove carriage returns
Foswiki::Serialise::deserialise( $text, 'Embedded', $topicObject );

Expand Down
9 changes: 9 additions & 0 deletions core/lib/Foswiki.spec
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,15 @@ $Foswiki::cfg{PluralToSingular} = $TRUE;
# Leave this undefined to use the default of utf-8 encoding.
# $Foswiki::cfg{Store}{Encoding} = undef;

# **BOOLEAN LABEL="NFC Normalize Filenames" **
# Foswiki uses NFC normalization for all network operations, but assumes
# that the file system is also NFC normalized. Some systems such as OSx
# enforce NFD normalization for filenames. If Foswiki is installed on one
# of these sysetms, or accesses such a system via a remote file system
# like NFS, then all directory / filename read operations must be NFC
# normalized.
$Foswiki::cfg{NFCNormalizeFilenames} = $FALSE;

# **PERL LABEL="Implementation Classes" EXPERT**
# Customisation of the Foswiki Store implementation. This allows
# extension modules to hook into the store implementation at a very low level.
Expand Down
8 changes: 7 additions & 1 deletion core/lib/Foswiki/Store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use Assert;
use Foswiki ();
use Foswiki::Sandbox ();
use HTML::Entities ();
use Unicode::Normalize qw(NFC);

BEGIN {
if ( $Foswiki::cfg{UseLocale} ) {
Expand Down Expand Up @@ -251,13 +252,18 @@ currently selected {Store}{Encoding} (or UTF-8 if none is set)
into perl characters (unicode). May die if $octets contains
an invalid byte sequence for the encoding.
This utility function should not be used to decode topic text.
For performance reasons, we don't need to NFC normalize file contents,
only the filenames themselves.
=cut

sub decode {
return $_[0] unless defined $_[0];
my $s = $_[0];
return Encode::decode( $Foswiki::cfg{Store}{Encoding} || 'utf-8',
my $decoded = Encode::decode( $Foswiki::cfg{Store}{Encoding} || 'utf-8',
$s, Encode::FB_CROAK );
return ( $Foswiki::cfg{NFCNormalizeFilenames} ) ? NFC($decoded) : $decoded;
}

=begin TML
Expand Down

0 comments on commit 571a359

Please sign in to comment.