From b45c0e8999e5970fe5f23df18c6992c188aae9a3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 30 Apr 2024 09:59:23 +0100 Subject: [PATCH] Bug 5920: (QA follow-up) Switch to use existing dependancy We already have a scrubber module we can use; This patch switches us from the newly introduced dependancy to using the existing and well respected Scrubber we already have. Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- cpanfile | 1 - reports/guided_reports.pl | 32 ++++++++++++++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/cpanfile b/cpanfile index 06dce372fe..d3c28e62d7 100644 --- a/cpanfile +++ b/cpanfile @@ -52,7 +52,6 @@ requires 'Getopt::Std', '1.05'; requires 'HTML::Entities', '3.69'; requires 'HTML::FormatText', '1.23'; requires 'HTML::Scrubber', '0.08'; -requires 'HTML::Restrict', ''; requires 'HTTP::Cookies', '1.39'; requires 'HTTP::OAI', '3.2'; requires 'HTTP::Request::Common', '1.26'; diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index a4e6bdd3bb..61c29a0c0f 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -40,7 +40,7 @@ use Koha::Util::OpenDocument qw( generate_ods ); use Koha::Notice::Templates; use Koha::TemplateUtils qw( process_tt ); use C4::ClassSource qw( GetClassSources ); -use HTML::Restrict; +use C4::Scrubber; =head1 NAME @@ -620,8 +620,8 @@ elsif ($op eq 'export'){ my @sql_params = $input->multi_param('sql_params'); my $format = $input->param('format'); my $reportname = $input->param('reportname'); - my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format" ; - my $hr = HTML::Restrict->new(); + my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format"; + my $scrubber = C4::Scrubber->new(); ($sql, undef) = $report->prep_report( \@param_names, \@sql_params ); my ( $sth, $q_errors ) = execute_query( { sql => $sql, report_id => $report_id } ); @@ -630,9 +630,9 @@ elsif ($op eq 'export'){ if ($format eq 'tab') { $type = 'application/octet-stream'; $content .= join("\t", header_cell_values($sth)) . "\n"; - $content = $hr->process(Encode::decode('UTF-8', $content)); - while (my $row = $sth->fetchrow_arrayref()) { - $content .= join("\t", $hr->process(@$row)) . "\n"; + $content = $scrubber->scrub( Encode::decode( 'UTF-8', $content ) ); + while ( my $row = $sth->fetchrow_arrayref() ) { + $content .= join( "\t", $scrubber->scrub(@$row) ) . "\n"; } } else { if ( $format eq 'csv' ) { @@ -640,18 +640,18 @@ elsif ($op eq 'export'){ $type = 'application/csv'; my $csv = Text::CSV::Encoded->new({ encoding_out => 'UTF-8', sep_char => $delimiter}); $csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag(); - if ($csv->combine(header_cell_values($sth))) { - $content .= $hr->process(Encode::decode('UTF-8', $csv->string())) . "\n"; + if ( $csv->combine( header_cell_values($sth) ) ) { + $content .= $scrubber->scrub( Encode::decode( 'UTF-8', $csv->string() ) ) . "\n"; } else { - push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() } ; + push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() }; } - while (my $row = $sth->fetchrow_arrayref()) { - if ($csv->combine(@$row)) { - $content .= $hr->process($csv->string()) . "\n"; + while ( my $row = $sth->fetchrow_arrayref() ) { + if ( $csv->combine(@$row) ) { + $content .= $scrubber->scrub( $csv->string() ) . "\n"; } else { - push @$q_errors, { combine => $csv->error_diag() } ; + push @$q_errors, { combine => $csv->error_diag() }; } } } @@ -667,10 +667,10 @@ elsif ($op eq 'export'){ # Other line in Unicode my $sql_rows = $sth->fetchall_arrayref(); - foreach my $sql_row ( @$sql_rows ) { + foreach my $sql_row (@$sql_rows) { my @content_row; - foreach my $sql_cell ( @$sql_row ) { - push @content_row, $hr->process(Encode::encode( 'UTF8', $sql_cell )); + foreach my $sql_cell (@$sql_row) { + push @content_row, $scrubber->scrub( Encode::encode( 'UTF8', $sql_cell ) ); } push @$ods_content, \@content_row; -- 2.39.5