Skip to content

Commit

Permalink
Item1682: SEARCH does not work well with format being blank
Browse files Browse the repository at this point in the history
Now it does


git-svn-id: http://svn.foswiki.org/branches/Release01x00@4025 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Jun 3, 2009
1 parent 44952ab commit 5bb19c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
11 changes: 11 additions & 0 deletions UnitTestContrib/test/unit/Fn_SEARCH.pm
Expand Up @@ -252,6 +252,17 @@ sub verify_multiple_and_footer_with_ntopics_and_nhits {
$result );
}

sub verify_footer_with_ntopics_empty_format {
my $this = shift;

my $result = $this->{twiki}->handleCommonTags(
'%SEARCH{"name~\'*Topic\'" type="query" nonoise="on" footer="Total found: $ntopics" format="" separator=""}%',
$this->{test_web}, $this->{test_topic}
);

$this->assert_str_equals( "Total found: 3", $result );
}

sub verify_regex_match {
my $this = shift;

Expand Down
27 changes: 14 additions & 13 deletions core/lib/Foswiki/Search.pm
Expand Up @@ -363,7 +363,8 @@ sub searchWeb {
my $caseSensitive = Foswiki::isTrue( $params{casesensitive} );
my $excludeTopic = $params{excludetopic} || '';
my $doExpandVars = Foswiki::isTrue( $params{expandvariables} );
my $format = defined $params{format} ? $params{format} : '';
my $formatDefined = defined $params{format};
my $format = $params{format};
my $header = $params{header};
my $footer = $params{footer};
my $inline = $params{inline};
Expand All @@ -377,11 +378,11 @@ sub searchWeb {
# now deprecated option 'inline' is used combined with 'format'
my $noHeader = !defined($header)
&& Foswiki::isTrue( $params{noheader}, $nonoise )
|| ( !$header && $format && $inline );
|| ( !$header && $formatDefined && $inline );

my $noFooter = !defined($footer)
&& Foswiki::isTrue( $params{nofooter}, $nonoise )
|| ( !$footer && $format && $inline );
|| ( !$footer && $formatDefined && $inline );

my $noSearch = Foswiki::isTrue( $params{nosearch}, $nonoise );
my $noSummary = Foswiki::isTrue( $params{nosummary}, $nonoise );
Expand Down Expand Up @@ -504,14 +505,14 @@ sub searchWeb {
my $originalSearch = $searchString;
my $spacedTopic;

if ($format) {
if ( $formatDefined ) {
$template = 'searchformat';
}
elsif ($template) {
elsif ( $template ) {

# template definition overrides book and rename views
}
elsif ($doBookView) {
elsif ( $doBookView ) {
$template = 'searchbookview';
}
else {
Expand Down Expand Up @@ -807,7 +808,7 @@ sub searchWeb {
my ( $meta, $text );

# Special handling for format='...'
if ($format) {
if ( $formatDefined ) {
( $meta, $text ) =
_getTextAndMeta( $this, $topicInfo, $web, $topic );

Expand Down Expand Up @@ -853,7 +854,7 @@ sub searchWeb {
$wikiusername = "$Foswiki::cfg{UsersWebName}.UnknownUser"
unless defined $wikiusername;

if ($format) {
if ( $formatDefined ) {
$out = $format;
$out =~ s/\$web/$web/gs;
$out =~ s/\$topic\(([^\)]*)\)/Foswiki::Render::breakName(
Expand Down Expand Up @@ -933,7 +934,7 @@ sub searchWeb {
$out =~ s/%TEXTHEAD%/$text/go;
}
elsif ($format) {
elsif ( $formatDefined ) {
$out =~
s/\$summary(?:\(([^\)]*)\))?/$renderer->makeTopicSummary( $text, $topic, $web, $1 )/ges;
$out =~
Expand Down Expand Up @@ -1006,8 +1007,8 @@ s/\$pattern\((.*?\s*\.\*)\)/_extractPattern( $text, $1 )/ges;
}
}
#don't expand if a format is specified - it breaks tables and stuff
unless ($format) {
# don't expand if a format is specified - it breaks tables and stuff
unless ( $formatDefined ) {
$out = $renderer->getRenderedVersion( $out, $web, $topic );
}
Expand Down Expand Up @@ -1036,7 +1037,7 @@ s/\$pattern\((.*?\s*\.\*)\)/_extractPattern( $text, $1 )/ges;
$afterText =~ s/\$nhits/$nhits/gs;
$afterText =
$session->handleCommonTags( $afterText, $web, $homeTopic );
if ( $inline || $format ) {
if ( $inline || $formatDefined ) {
$afterText =~ s/\n$//os; # remove trailing new line
}
Expand Down Expand Up @@ -1072,7 +1073,7 @@ s/\$pattern\((.*?\s*\.\*)\)/_extractPattern( $text, $1 )/ges;
} # end of: foreach my $web ( @webs )
return '' if ( $ttopics == 0 && $zeroResults );
if ( $format && !$finalTerm ) {
if ( $formatDefined && !$finalTerm ) {
if ($separator) {
$separator = quotemeta($separator);
$searchResult =~ s/$separator$//s; # remove separator at end
Expand Down

0 comments on commit 5bb19c6

Please sign in to comment.