From e413db6083e57ec127d59a2e3be100fd06ee8e94 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 1 Apr 2024 16:03:37 +0000 Subject: [PATCH] Bug 36328: (QA follow-up) Expand tests and reorder elements to clarify differences Also tidy Signed-off-by: Nick Clemens (cherry picked from commit 42d388c80fcdd98c2594ad7b111b8e40c991388a) Signed-off-by: Fridolin Somers --- C4/Scrubber.pm | 12 ++++++------ t/Scrubber.t | 12 ++++++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/C4/Scrubber.pm b/C4/Scrubber.pm index e265c8dcc0..ccfa830585 100644 --- a/C4/Scrubber.pm +++ b/C4/Scrubber.pm @@ -27,10 +27,10 @@ use HTML::Scrubber; use C4::Context; my %scrubbertypes = ( - default => {}, # place holder, default settings are below as fallbacks in call to constructor - tag => {}, # uses defaults + default => {}, # place holder, default settings are below as fallbacks in call to constructor + tag => {}, # uses defaults comment => { allow => [qw( br b i em big small strong )], }, - note => { allow => [qw[ p b i u hr br em big small strong span div ]] }, + note => { allow => [qw[ br b i em big small strong u hr span div p ]] }, staff => { default => [ 1 => { '*' => 1 } ], comment => 1, @@ -46,11 +46,11 @@ sub new { } my $settings = $scrubbertypes{$type}; my $scrubber = HTML::Scrubber->new( - allow => exists $settings->{allow} ? $settings->{allow} : [], - rules => exists $settings->{rules} ? $settings->{rules} : [], + allow => exists $settings->{allow} ? $settings->{allow} : [], + rules => exists $settings->{rules} ? $settings->{rules} : [], default => exists $settings->{default} ? $settings->{default} : [ 0 => { '*' => 0 } ], comment => exists $settings->{comment} ? $settings->{comment} : 0, - note => exists $settings->{note} ? $settings->{note} : 0, + note => exists $settings->{note} ? $settings->{note} : 0, process => 0, ); return $scrubber; diff --git a/t/Scrubber.t b/t/Scrubber.t index 3a43522ad0..e04fd2e0d9 100755 --- a/t/Scrubber.t +++ b/t/Scrubber.t @@ -3,7 +3,7 @@ use Modern::Perl; $| = 1; -use Test::More tests => 30; +use Test::More tests => 31; use Test::Warn; BEGIN { @@ -82,4 +82,12 @@ if ($@) { pass("Test should have failed on entry of 'Client' and it did. YAY!"); } -is( C4::Scrubber->new('note')->scrub('Allow span'), 'Allow span' ); +my $scrub_text = + '

bolditalemphaticembiggenshrinkstrongbad
under


'; +my $scrub_comment = + 'bolditalemphaticembiggenshrinkstrongbad
under'; +is( C4::Scrubber->new('comment')->scrub($scrub_text), $scrub_comment, "Comment scrubber removes expected elements" ); +is( + C4::Scrubber->new('note')->scrub($scrub_text), $scrub_text, + "Note scrubber removes (additional) expected elements" +); -- 2.39.5