From: <de...@de...> - 2007-04-27 09:50:20
|
Author: CrawfordCurrie Date: 2007-04-27 04:50:20 -0500 (Fri, 27 Apr 2007) New Revision: 13539 Modified: twiki/branches/MAIN/lib/TWiki.pm twiki/branches/MAIN/test/unit/Fn_INCLUDE.pm Log: Item3158: corrected behaviour of section include, and added unit test Modified: twiki/branches/MAIN/lib/TWiki.pm =================================================================== --- twiki/branches/MAIN/lib/TWiki.pm 2007-04-27 09:16:51 UTC (rev 13538) +++ twiki/branches/MAIN/lib/TWiki.pm 2007-04-27 09:50:20 UTC (rev 13539) @@ -2960,7 +2960,8 @@ return ''; } - # remove everything before and after the selected include block + # remove everything before and after the default include block unless + # a section is explicitly defined if( !$section ) { $text =~ s/.*?%STARTINCLUDE%//s; $text =~ s/%STOPINCLUDE%.*//s; @@ -2970,8 +2971,8 @@ my( $ntext, $sections ) = parseSections( $text ); my $interesting = ( defined $section ); - if( scalar( @$sections )) { - # Rebuild the text from the sections + if( $interesting || scalar( @$sections )) { + # Rebuild the text from the interesting sections $text = ''; foreach my $s ( @$sections ) { if( $section && $s->{type} eq 'section' && Modified: twiki/branches/MAIN/test/unit/Fn_INCLUDE.pm =================================================================== --- twiki/branches/MAIN/test/unit/Fn_INCLUDE.pm 2007-04-27 09:16:51 UTC (rev 13538) +++ twiki/branches/MAIN/test/unit/Fn_INCLUDE.pm 2007-04-27 09:50:20 UTC (rev 13539) @@ -90,4 +90,36 @@ } +# Test include of a section when there is no such section in the included +# topic +sub test_3158 { + my $this = shift; + my $includedTopic = "TopicToInclude"; + $this->{twiki}->{store}->saveTopic( + $this->{twiki}->{user}, $this->{other_web}, + $includedTopic, <<THIS); +Snurfle +%STARTSECTION{"suction"}% +Such a section! +%ENDSECTION{"suction"}% +Out of scope +THIS + my $text = $this->{twiki}->handleCommonTags( + "%INCLUDE{\"$this->{other_web}.$includedTopic\" section=\"suction\"}%", + $this->{test_web}, $this->{test_topic}); + $this->assert_str_equals("\nSuch a section!\n", $text); + + $this->{twiki}->{store}->saveTopic( + $this->{twiki}->{user}, $this->{other_web}, + $includedTopic, <<THIS); +%STARTSECTION{"nosuction"}% +No such section! +%ENDSECTION{"nosuction"}% +THIS + $text = $this->{twiki}->handleCommonTags( + "%INCLUDE{\"$this->{other_web}.$includedTopic\" section=\"suction\"}%", + $this->{test_web}, $this->{test_topic}); + $this->assert_str_equals('', $text); +} + 1; |