[Koha-patches] [PATCH] Bug 6085 : utf8 fixed for xslt, and parameters, broken for utf8 included in templates

Chris Cormack chrisc at catalyst.net.nz
Mon Apr 11 02:48:13 CEST 2011


---
 C4/Output.pm                     |    1 +
 C4/Templates.pm                  |    2 ++
 misc/translator/TTParser.pm      |   17 +++--------------
 misc/translator/tmpl_process3.pl |    1 +
 4 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/C4/Output.pm b/C4/Output.pm
index 769081c..0adc163 100644
--- a/C4/Output.pm
+++ b/C4/Output.pm
@@ -463,6 +463,7 @@ sub output_with_http_headers($$$$;$) {
     # remove SUDOC specific NSB NSE
     $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);
 
     print $query->header($options), $data;
diff --git a/C4/Templates.pm b/C4/Templates.pm
index ff47c88..9169f41 100644
--- a/C4/Templates.pm
+++ b/C4/Templates.pm
@@ -105,6 +105,7 @@ sub output {
         $vars->{$k} = $self->{VARS}->{$k};
     }
     my $data;
+#    binmode( STDOUT, ":utf8" );
     $template->process( $self->filename, $vars, \$data )
       || die "Template process failed: ", $template->error();
     return $data;
@@ -182,6 +183,7 @@ sub param {
         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;
diff --git a/misc/translator/TTParser.pm b/misc/translator/TTParser.pm
index 9001cb2..94000bc 100755
--- a/misc/translator/TTParser.pm
+++ b/misc/translator/TTParser.pm
@@ -57,8 +57,6 @@ sub text{
     my $is_cdata = shift;
 
     while($work){
-#            warn "in text line is $line work is $work";
-#        return if $work =~ m/^\s*$/;
         # if there is a template_toolkit tag
         if( $work =~ m/\[%.*?\]/ ){
             #everything before this tag is text (or possibly CDATA), add a text token to tokens if $`
@@ -71,11 +69,10 @@ sub text{
             my $t = TmplToken->new( $&, TmplTokenType::DIRECTIVE, $line, $self->{filename} );
             push @tokens, $t;
 
-            #put work still to do back into work
+            # put work still to do back into work
             $work = $' ? $' : 0;
         } else {
-#            warn "in the text else work is now $work";
-            #If there is some left over work, treat it as text token
+            # If there is some left over work, treat it as text token
             my $t = TmplToken->new( $work, ($is_cdata? TmplTokenType::CDATA : TmplTokenType::TEXT), $line, $self->{filename} );
             push @tokens, $t;
             last;
@@ -88,7 +85,6 @@ sub declaration {
     my $line = shift;
     my $work = shift; #original text
     my $is_cdata = shift;
-#      warn "declaration work is $work";
     my $t = TmplToken->new( $work, ($is_cdata? TmplTokenType::CDATA : TmplTokenType::TEXT), $line, $self->{filename} );
     push @tokens, $t;  
 }      
@@ -98,7 +94,6 @@ sub comment {
     my $line = shift;
     my $work = shift; #original text
     my $is_cdata = shift;
-#      warn "comment work is $work";
     my $t = TmplToken->new( $work, ($is_cdata? TmplTokenType::CDATA : TmplTokenType::TEXT), $line, $self->{filename} );
     push @tokens, $t;  
 }      
@@ -108,7 +103,6 @@ sub default {
     my $line = shift;
     my $work = shift; #original text
     my $is_cdata = shift;
-#      warn "comment work is $work";
     my $t = TmplToken->new( $work, ($is_cdata? TmplTokenType::CDATA : TmplTokenType::TEXT), $line, $self->{filename} );
     push @tokens, $t;  
 }      
@@ -121,10 +115,6 @@ sub start{
     my $tag = shift;
     my $hash = shift; #hash of attr/value pairs
     my $text = shift; #origional text
-#      warn "in start text is $text";
-    # return if ! $interesting_tags{$tag};
-    # was $hash->{$key}
-    # print "#### " . $self->{filename}  . " " . $tag . "####\n";
     my $t = TmplToken->new( $text, TmplTokenType::TAG, $line, $self->{filename});
     my %attr;
     # tags seem to be uses in an 'interesting' way elsewhere..
@@ -143,8 +133,7 @@ sub end{
     my $tag = shift;
     my $hash = shift;
     my $text = shift;
-#  warn "in end text is $text";  
-  # what format should this be in?
+    # what format should this be in?
     my $t = TmplToken->new( $text, TmplTokenType::TAG, $line, $self->{filename} );
     my %attr;
     # tags seem to be uses in an 'interesting' way elsewhere..
diff --git a/misc/translator/tmpl_process3.pl b/misc/translator/tmpl_process3.pl
index dd6cf5c..15c81aa 100755
--- a/misc/translator/tmpl_process3.pl
+++ b/misc/translator/tmpl_process3.pl
@@ -394,6 +394,7 @@ if ($action eq 'create')  {
             mkdir_recursive($targetdir) unless -d $targetdir;
             print STDERR "Creating $target...\n" unless $quiet;
             open( OUTPUT, ">$target" ) || die "$target: $!\n";
+            binmode( OUTPUT, ":utf8" );
             text_replace( $h, *OUTPUT );
             close OUTPUT;
         } else {
-- 
1.5.6.5



More information about the Koha-patches mailing list