diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 65973aa69..03d112257 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.6.10 + - added test for splitTag function recently added to HTML module - fixed #9455: fixed synopsis to pick out html paragraphs, fixed FeedPP fields to scalar when blank - fixed: With autocommit and no comments on, making a shortcut of an asset takes you to that asset's view. - fixed #9506: Choose billing address diff --git a/lib/WebGUI/HTML.pm b/lib/WebGUI/HTML.pm index 3d213ac59..73d82f0f2 100644 --- a/lib/WebGUI/HTML.pm +++ b/lib/WebGUI/HTML.pm @@ -37,7 +37,7 @@ A package for manipulating and massaging HTML. $html = WebGUI::HTML::html2text($html); $html = WebGUI::HTML::makeAbsolute($session, $html); $html = WebGUI::HTML::processReplacements($session, $html); - $html = WebGUI::HTML::splitTag([$tag,]$html[,$count]); # defaults to ( 'p', $html, 0 ) + $html = WebGUI::HTML::splitTag([$tag,]$html[,$count]); # defaults to ( 'p', $html, 1 ) =head1 METHODS @@ -414,7 +414,7 @@ The block of HTML text that will be disected =head3 count -How many items do we want? defaults to 1; returns 1 non-blank item +How many items do we want? defaults to 1; returns 1 non-blank item; -1 returns all items =cut @@ -423,15 +423,13 @@ sub splitTag { my $tag = shift; my $html = shift; my $count = shift || 1; - if( not defined $html or $html =~ /^(\d+)$/ ) { + if( not defined $html or $html =~ /^(-?\d+)$/ ) { $count = $html if $1; $html = $tag; $tag = 'p'; # the default tag is 'p' -- grabs a paragraph } my @result; - $html =~ s/\ //g; # get rid of all non-breaking spaces - my $p = HTML::TokeParser->new(\$html); while (my $token = $p->get_tag($tag)) { @@ -441,7 +439,8 @@ sub splitTag { last if @result == $count; # if we have a full count then quit } - return @result; + return @result if wantarray; + return $result[0]; } 1; diff --git a/t/splitTag.t b/t/splitTag.t new file mode 100644 index 000000000..db11d222a --- /dev/null +++ b/t/splitTag.t @@ -0,0 +1,132 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2008 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use FindBin; +use strict; +use lib "$FindBin::Bin/lib"; + +use WebGUI::Test; +use WebGUI::HTML; +use WebGUI::Session; + +use Test::More; # increment this value for each test you create + +my $session = WebGUI::Test->session; + +# the style param below refers to how the callis made. the function has two optional params +# by testing with each style we can test the default for thsee params. +# also array/scalar return type are tested. + +# call type = 1: all three params; return array +# call type = 2: only tag and text; return scalar +# call type = 3: only text and count; return array +# call type = 4: only the text; return scalar + +my @testArray = ( + { + inputText => q!
First Paragraph
Second Paragraph
!, + output => q!First Paragraph!, + style => 1, + tag => 'p', + count => 1, + comment => 'get one paragraph, no defaults', + }, + { + inputText => q!First Paragraph
Second Paragraph
!, + output => q!First Paragraph!, + style => 4, + tag => 'p', + count => 1, + comment => 'get one paragraph, all defaults', + }, + { + inputText => q!First Paragraph
Second Paragraph
!, + output => q!First Paragraph;Second Paragraph!, + style => 1, + tag => 'p', + count => -1, + comment => 'get all paragraphs, no defaults', + }, + { + inputText => q!First Paragraph
Second Paragraph
!, + output => q!First Paragraph;Second Paragraph!, + style => 3, + tag => 'p', + count => -1, + comment => 'get all paragraphs, default tag', + }, + { + inputText => q!
First nonblank Paragraph
Second Paragraph
!, + output => q!First nonblank Paragraph!, + style => 4, + tag => 'p', + count => -1, + comment => 'get nonblank paragraph, all defaults', + }, + { + inputText => q!
First nonblank Paragraph
Second Paragraph
!, + output => q!First nonblank Paragraph!, + style => 4, + tag => 'p', + count => -1, + comment => 'get nonblank(nbsp) paragraph, all defaults', + }, + { + inputText => q!