Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7a0da5ac

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID 7a0da5ac43efdef3428d9268c141a747b3d0c989
  • Vorgänger 23f79a87
  • Nachfolger c203c637

CSV-Export für ISO- und UTF-8, mit und ohne FastCGI gefixt

Fix für Bug 1535.

Unterschiede anzeigen:

SL/ReportGenerator.pm
686 686
  }
687 687
}
688 688

  
689
sub unescape_string {
690
  my ($self, $text, $do_iconv) = @_;
689
sub _handle_quoting_and_encoding {
690
  my ($self, $text, $do_unquote) = @_;
691 691

  
692
  $text = $main::locale->unquote_special_chars('HTML', $text);
693
  $text = $::locale->{iconv}->convert($text) if $do_iconv;
692
  $text = $main::locale->unquote_special_chars('HTML', $text) if $do_unquote;
693
  $text = Encode::encode('UTF-8', $text) if $::locale->is_utf8;
694 694

  
695 695
  return $text;
696 696
}
697 697

  
698 698
sub generate_csv_content {
699
  my $self = shift;
699
  my $self   = shift;
700
  my $stdout = ($::dispatcher->get_standard_filehandles)[1];
701

  
702
  # Text::CSV_XS seems to downgrade to bytes already (see
703
  # SL/FCGIFixes.pm). Therefore don't let FCGI do that again.
704
  $::locale->with_raw_io($stdout, sub { $self->_generate_csv_content($stdout) });
705
}
706

  
707
sub _generate_csv_content {
708
  my ($self, $stdout) = @_;
700 709

  
701 710
  my %valid_sep_chars    = (';' => ';', ',' => ',', ':' => ':', 'TAB' => "\t");
702 711
  my %valid_escape_chars = ('"' => 1, "'" => 1);
......
718 727

  
719 728
  my @visible_columns = $self->get_visible_columns('CSV');
720 729

  
721
  my $stdout;
722
  open $stdout, '>-';
723
  binmode $stdout, ':encoding(utf8)' if $::locale->is_utf8;
724

  
725 730
  if ($opts->{headers}) {
726 731
    if (!$self->{custom_headers}) {
727
      $csv->print($stdout, [ map { $self->unescape_string($self->{columns}->{$_}->{text}, 1) } @visible_columns ]);
732
      $csv->print($stdout, [ map { $self->_handle_quoting_and_encoding($self->{columns}->{$_}->{text}, 1) } @visible_columns ]);
728 733

  
729 734
    } else {
730 735
      foreach my $row (@{ $self->{custom_headers} }) {
......
732 737

  
733 738
        foreach my $col (@{ $row }) {
734 739
          my $num_output = ($col->{colspan} && ($col->{colspan} > 1)) ? $col->{colspan} : 1;
735
          push @{ $fields }, ($self->unescape_string($col->{text})) x $num_output;
740
          push @{ $fields }, ($self->_handle_quoting_and_encoding($col->{text}, 1)) x $num_output;
736 741
        }
737 742

  
738 743
        $csv->print($stdout, $fields);
......
754 759
        my $num_output = ($row->{$col}{colspan} && ($row->{$col}->{colspan} > 1)) ? $row->{$col}->{colspan} : 1;
755 760
        $skip_next     = $num_output - 1;
756 761

  
757
        push @data, join($eol, map { s/\r?\n/$eol/g; $_ } @{ $row->{$col}->{data} });
762
        push @data, join($eol, map { s/\r?\n/$eol/g; $self->_handle_quoting_and_encoding($_, 0) } @{ $row->{$col}->{data} });
758 763
        push @data, ('') x $skip_next if ($skip_next);
759 764
      }
760 765

  

Auch abrufbar als: Unified diff