Fix encoding issues in HTML report files
authorDan Scott <dscott@laurentian.ca>
Tue, 17 Nov 2015 17:11:19 +0000 (12:11 -0500)
committerDan Scott <dscott@laurentian.ca>
Tue, 17 Nov 2015 17:13:06 +0000 (12:13 -0500)
Opening the files without the utf-8 encoding pragma resulted in
corrupted UTF8 output.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/reporter/clark-kent.pl

index 80a320c..06dc44e 100755 (executable)
@@ -448,6 +448,7 @@ sub build_html {
        my $r = shift;
 
        my $index = new FileHandle (">$file") or die "Cannot write to '$file'";
+       open(my $index, ">:encoding(utf-8)", "$file") or die "Cannot write to '$file'";
 
        my $tdata = OpenSRF::Utils::JSON->JSON2perl( $r->{report}->{template}->{data} );
        
@@ -518,7 +519,7 @@ sub build_html {
 
        if ($r->{html_format}) {
                # create the raw output html file
-               my $raw = new FileHandle (">$file.raw.html") or die "Cannot write to '$file.raw.html'";
+               open(my $raw, ">:encoding(utf-8)", "$file.raw.html") or die "Cannot write to '$file.raw.html'";
                print $raw "<html><head><meta charset='utf-8'><title>$$r{report}{name}</title>";
 
                print $raw <<'          CSS';
@@ -541,7 +542,7 @@ sub build_html {
 
                print $raw '</tbody></table></body></html>';
        
-               $raw->close;
+               close($raw);
        }
 
        # Time for a pie chart
@@ -573,7 +574,7 @@ sub build_html {
        # and that's it!
        print $index '</body></html>';
        
-       $index->close;
+       close($index);
 }
 
 sub draw_pie {