Bug 6085 : utf8 fixed for xslt, and parameters, broken for utf8 included in templates
authorChris Cormack <chrisc@catalyst.net.nz>
Mon, 11 Apr 2011 00:48:13 +0000 (12:48 +1200)
committerChris Cormack <chrisc@catalyst.net.nz>
Mon, 11 Apr 2011 00:58:05 +0000 (12:58 +1200)
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
C4/Output.pm
C4/Templates.pm
misc/translator/TTParser.pm
misc/translator/tmpl_process3.pl

index 769081c..0adc163 100644 (file)
@@ -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;
index ff47c88..9169f41 100644 (file)
@@ -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;
index 9001cb2..94000bc 100755 (executable)
@@ -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..
index dd6cf5c..15c81aa 100755 (executable)
@@ -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 {