Bug 6085 : Fixing the utf8 weirdness

I am not very happy with this fix, but it does mean the template are
translatable and we don't get double encoding issues with them anymore

Please test

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
This commit is contained in:
Chris Cormack 2011-04-11 15:58:18 +12:00
parent 256cc9196c
commit 7efaafe132
2 changed files with 46 additions and 4 deletions

View File

@ -464,7 +464,10 @@ sub output_with_http_headers($$$$;$) {
$data =~ s/\x{C2}\x{98}|\x{C2}\x{9C}/ /g;
$data =~ s/\x{C2}\x{88}|\x{C2}\x{89}/ /g;
utf8::encode($data) if utf8::is_utf8($data);
# We can't encode here, that will double encode our templates, and xslt
# We need to fix the encoding as it comes out of the database, or when we pass the variables to templates
# utf8::encode($data) if utf8::is_utf8($data);
print $query->header($options), $data;
}

View File

@ -100,9 +100,19 @@ sub output {
$vars->{opacsmallimage} = C4::Context->preference('opacsmallimage');
$vars->{opacstylesheet} = C4::Context->preference('opacstylesheet');
#add variables set via param to $vars for processing
# add variables set via param to $vars for processing
# and clean any utf8 mess
for my $k ( keys %{ $self->{VARS} } ) {
$vars->{$k} = $self->{VARS}->{$k};
if (ref($vars->{$k}) eq 'ARRAY'){
utf8_arrayref($vars->{$k});
}
elsif (ref($vars->{$k}) eq 'HASH'){
uft8_hashref($vars->{$k});
}
else {
utf8::encode($vars->{$k}) if utf8::is_utf8($vars->{$k});
}
}
my $data;
# binmode( STDOUT, ":utf8" );
@ -111,6 +121,37 @@ sub output {
return $data;
}
sub utf8_arrayref {
my $arrayref = shift;
foreach my $element (@$arrayref){
if (ref($element) eq 'ARRAY'){
utf8_arrayref($element);
next;
}
if (ref($element) eq 'HASH'){
utf8_hashref($element);
next;
}
utf8::encode($element) if utf8::is_utf8($element);
}
}
sub utf8_hashref {
my $hashref = shift;
for my $key (keys %{$hashref}){
if (ref($hashref->{$key}) eq 'ARRAY'){
utf8_arrayref($hashref->{$key});
next;
}
if (ref($hashref->{$key}) eq 'HASH'){
utf8_hashref($hashref->{$key});
next;
}
utf8::encode($hashref->{$key}) if utf8::is_utf8($hashref->{$key});
}
}
# FIXME - this is a horrible hack to cache
# the current known-good language, temporarily
# put in place to resolve bug 4403. It is
@ -182,8 +223,6 @@ sub param {
while (@_) {
my $key = shift;
my $val = shift;
utf8::encode($val) if utf8::is_utf8($val);
utf8::decode($val) if $key eq "XSLTBloc";
if ( ref($val) eq 'ARRAY' && !scalar @$val ) { $val = undef; }
elsif ( ref($val) eq 'HASH' && !scalar %$val ) { $val = undef; }
$self->{VARS}->{$key} = $val;