Skip to content

Commit

Permalink
Item727: data loss issue when missing anchor or location
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@1984 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Jan 15, 2009
1 parent b61b82b commit 950afb1
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 5 deletions.
1 change: 1 addition & 0 deletions CommentPlugin/data/System/CommentPlugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ Another great extension from the <a style="text-decoration:none" href="http://wi
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Plugin Version: | 13 Jan 2009 %$VERSION% |
| Change History: | |
| 15 Jan 2008 | Foswikitask:Item727 - data loss issue when missing anchor or location |
| 13 Jan 2009 | Foswikitask:736 Make !CommentPlugin aware of CompareRevisionsAddOn bin script. |
| 16 Dec 2008 | Foswiki version |
| 03 Aug 2008 | The TWiki 4.2.1 release version |
Expand Down
7 changes: 7 additions & 0 deletions CommentPlugin/lib/Foswiki/Plugins/CommentPlugin/Comment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ sub _buildNewTopic {
$inpost = 1;
}
}
#make sure the anchor or location exits
if (defined($location) and not($text =~ /(?<!location\=\")($location)/)) {
undef $location;
}
if (defined($anchor) and not($text =~ /^($anchor\s)/)) {
undef $anchor;
}

unless( $nopost ) {
if( $position eq 'TOP' ) {
Expand Down
120 changes: 115 additions & 5 deletions CommentPlugin/test/unit/CommentPlugin/CommentPluginTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,24 @@ sub inputTest {
$anchor = '#'.$anchor;
$sattrs .= $anchor;
}
$sattrs .= '"';
$sattrs .= '" ';
}

my $url = "$Foswiki::cfg{DefaultUrlHost}$Foswiki::cfg{ScriptUrlPath}/save$Foswiki::cfg{ScriptSuffix}/$web/$topic";

if ( $location ) {
$sattrs .= ' location="'.$location.'"';
$sattrs .= ' location="'.$location.'" ';
}

$type = "bottom" unless ($type);
$sattrs .= 'type="'.$type.'" ';

my $commentref = '%COMMENT{type="'.$type.'" refmark="here"}%';
my $commentref = '%COMMENT{'.$sattrs.' refmark="here"}%';

# Build the target topic
my $sample = <<HERE;
TopOfTopic
%COMMENT{type="$type"}%
%COMMENT{$sattrs}%
HERE
if ($anchor ) {
$sample .= <<HERE;
Expand Down Expand Up @@ -204,11 +204,14 @@ HERE
$text = Foswiki::Func::readTopicText($web, $topic);
$this->assert_matches(qr/$comm/, $text, "$web.$topic: $text");

#uncomment this to debug what the actual output looks like.
#$this->assert_str_equals($sample, $text);

my $refexpr;
if ($anchor) {
$refexpr = $anchor;
} elsif ($location) {
$refexpr = "HereIsTheLocation";
$refexpr = $location;
} else {
$refexpr = $commentref;
}
Expand Down Expand Up @@ -421,4 +424,111 @@ HERE
$this->assert_matches(qr#>wibble</textarea>#, $html);
}


sub test_targetWebTopicAboveAnchor_Missing_Item727 {
my $this = shift;

my $sample = <<HERE;
before
%COMMENT{type="above" cols="100" target="%INCLUDINGTOPIC%#LatestComment"}%
after
HERE
$this->writeTopic($this->{test_web}, $this->{test_topic}, $sample);
my $pidx = 99;
my $html =
Foswiki::Plugins::CommentPlugin::Comment::_handleInput(
'remove="on"',
$this->{test_web},
$this->{test_topic},
\$pidx,
"The Message",
"",
"bottom");
$this->assert_matches(qr/<input type="hidden" name="comment_remove" value="99"/, $html);

# Compose the query
my $comm = "This is the comment";
my $query = new Unit::Request(
{
'comment_action' => 'save',
'comment_type' => 'above',
'comment' => $comm,
'comment_anchor' => '#LatestComment',
});
$query->path_info("/$this->{test_web}/$this->{test_topic}");

my $session = new Foswiki( $Foswiki::cfg{DefaultUserLoginName}, $query);
my $text = "Ignore this text";

# invoke the save handler
$this->capture(\&Foswiki::UI::Save::save, $session );

$text = Foswiki::Func::readTopicText($this->{test_web}, $this->{test_topic});
# make sure it hasn't changed
$text =~ s/^%META.*?\n//gm;
$this->assert_str_equals(<<HERE,
before
This is the comment
-- TemporaryCommentPluginTestsUsersWeb.WikiGuest - 15 Jan 2009
%COMMENT{type="above" cols="100" target="%INCLUDINGTOPIC%#LatestComment"}%
after
HERE
$text);
}


sub test_targetWebTopicBelowAnchor_Missing_Item727 {
my $this = shift;

my $sample = <<HERE;
before
%COMMENT{type="below" target="%INCLUDINGTOPIC%#LatestComment"}%
after
HERE
$this->writeTopic($this->{test_web}, $this->{test_topic}, $sample);
my $pidx = 99;
my $html =
Foswiki::Plugins::CommentPlugin::Comment::_handleInput(
'remove="on"',
$this->{test_web},
$this->{test_topic},
\$pidx,
"The Message",
"",
"bottom");
$this->assert_matches(qr/<input type="hidden" name="comment_remove" value="99"/, $html);

# Compose the query
my $comm = "This is the comment";
my $query = new Unit::Request(
{
'comment_action' => 'save',
'comment_type' => 'below',
'comment' => $comm,
'comment_anchor' => '#LatestComment',

});
$query->path_info("/$this->{test_web}/$this->{test_topic}");

my $session = new Foswiki( $Foswiki::cfg{DefaultUserLoginName}, $query);
my $text = "Ignore this text";

# invoke the save handler
$this->capture(\&Foswiki::UI::Save::save, $session );

$text = Foswiki::Func::readTopicText($this->{test_web}, $this->{test_topic});
# make sure it hasn't changed
$text =~ s/^%META.*?\n//gm;
$this->assert_str_equals(<<HERE,
before
%COMMENT{type="below" target="%INCLUDINGTOPIC%#LatestComment"}%
* This is the comment -- TemporaryCommentPluginTestsUsersWeb.WikiGuest - 15 Jan 2009
after
HERE
$text);
}

1;

0 comments on commit 950afb1

Please sign in to comment.