diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 88fa74ace..d2f37a821 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,6 +1,6 @@ 7.7.5 - Adding StoryManager. - - fixed #10223: Calendar List View Ignores Event Permissions (dhelsten) + - fixed #10226: html2text dropping text 7.7.4 - rfe: Extend DateTime for Week-Nrs (#9151) diff --git a/lib/WebGUI/HTML.pm b/lib/WebGUI/HTML.pm index e8f875c66..a05357024 100644 --- a/lib/WebGUI/HTML.pm +++ b/lib/WebGUI/HTML.pm @@ -227,7 +227,7 @@ my $text = ""; my $inside = {}; sub html2text { - my $html = shift; + my $html = shift . " "; $text = ""; $inside = {}; my $tagHandler = sub { diff --git a/t/HTML.t b/t/HTML.t index c88a282e7..fbdb151f9 100644 --- a/t/HTML.t +++ b/t/HTML.t @@ -96,7 +96,28 @@ my @macroParamSets = ( }, ); -my $numTests = scalar @filterSets + scalar @macroParamSets; +my @htmlTextSets = ( + { + inputText => q|I wish I could tell you that Andy fought the good fight.|, + output => q|I wish I could tell you that Andy fought the good fight.|, + comment => 'bare text', + }, + { + inputText => q|The man likes to play chess; let's get him some rocks. |, + output => q|The man likes to play chess; let's get him some rocks.|, + comment => 'bare text with ending space has that space removed', + }, + { + inputText => q|

Do you enjoy working in the laundry?

|, + output => qq|\nDo you enjoy working in the laundry?\n|, + comment => 'text in paragraph tag nested inside newlines', + }, +); + +my $numTests = scalar @filterSets + + scalar @macroParamSets + + scalar @htmlTextSets + ; plan tests => $numTests; @@ -109,3 +130,8 @@ foreach my $testSet (@macroParamSets) { WebGUI::HTML::makeParameterSafe(\$testSet->{inputText}); is($testSet->{inputText}, $testSet->{output}, $testSet->{comment}); } + +foreach my $testSet (@htmlTextSets) { + my $text = WebGUI::HTML::html2text($testSet->{inputText}); + is($text, $testSet->{output}, $testSet->{comment}); +}