Skip to content

Commit

Permalink
test for wiping comments with "0" and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kensanata committed Aug 29, 2015
1 parent 31c02d6 commit 4d8b028
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
33 changes: 25 additions & 8 deletions t/comments.t
Expand Up @@ -14,7 +14,7 @@

require 't/test.pl';
package OddMuse;
use Test::More tests => 38;
use Test::More tests => 43;

AppendStringToFile($ConfigFile, "\$CommentsPrefix = 'Comments on ';\n");

Expand Down Expand Up @@ -80,22 +80,39 @@ test_page($page, 'Can add comments with edit allowed eq 3');

AppendStringToFile($ConfigFile, "\$EditAllowed = 1;\n");

get_page('title=Yadda', 'aftertext=This%20is%20my%20comment.', 'username=Alex');
test_page(get_page('Yadda'), 'This is my comment.');
get_page('title=Yadda', 'aftertext=This%20is%20my%20comment%20on%20an%20ordinary%20page.', 'username=Alex');
test_page(get_page('Yadda'), 'This is my comment on an ordinary page\.');

get_page('title=Comments_on_Yadda', 'aftertext=This%20is%20my%20comment.', 'username=Alex');
test_page(get_page('Comments_on_Yadda'), 'This is my comment\.', '-- Alex');
get_page('title=Comments_on_Yadda', 'aftertext=This%20is%20my%20comment%20on%20a%20comment%20page.', 'username=Alex');
test_page(get_page('Comments_on_Yadda'), 'This is my comment on a comment page\.', '-- Alex');
test_page(get_page('action=rc raw=1'), 'title: Comments on Yadda',
'description: This is my comment.', 'generator: Alex');
'description: This is my comment on a comment page\.', 'generator: Alex');

# No wiping with empty comment

get_page('title=Comments_on_Yadda', 'aftertext=', 'username=Berta');
$page = get_page('Comments_on_Yadda');
test_page($page, 'This is my comment on a comment page\.');
test_page_negative('Berta');

# No wiping with a comment that evaluates to false

get_page('title=Comments_on_Yadda', 'aftertext=0', 'username=Berta');
test_page(get_page('Comments_on_Yadda'),
'This is my comment on a comment page\.',
'<p>0</p>',
'Berta');

# homepage
get_page('title=Comments_on_Yadda', 'aftertext=This%20is%20another%20comment.',
'username=Alex', 'homepage=http%3a%2f%2fwww%2eoddmuse%2eorg%2f');
xpath_test(get_page('Comments_on_Yadda'),
'//p[contains(text(),"This is my comment.")]',
'//p[contains(text(),"This is my comment on a comment page.")]', # not wiped
'//p[contains(text(),"This is another comment.")]', # not wiped
'//a[@class="url http outside"][@href="http://www.oddmuse.org/"][text()="Alex"]');

# variant without protocol
get_page('title=Comments_on_Yadda', 'aftertext=This%20is%20another%20comment.',
get_page('title=Comments_on_Yadda', 'aftertext=This%20is%20yet%20another%20comment.',
'username=Berta', 'homepage=alexschroeder%2ech');
xpath_test(get_page('Comments_on_Yadda'),
'//a[@class="url http outside"][@href="http://alexschroeder.ch"][text()="Berta"]');
Expand Down
6 changes: 3 additions & 3 deletions wiki.pl
Expand Up @@ -3603,7 +3603,7 @@ sub DoPost {
eval { require MIME::Base64; $_ = MIME::Base64::encode($content) };
$string = "#FILE $type $encoding\n" . $_;
} else { # ordinary text edit
$string = AddComment($old, $comment) if $comment;
$string = AddComment($old, $comment) if defined $comment;
if ($comment and substr($string, 0, length($DeletedPage)) eq $DeletedPage) { # look ma, no regexp!
$string = substr($string, length($DeletedPage)); # undelete pages when adding a comment
}
Expand All @@ -3625,7 +3625,7 @@ sub DoPost {
my $oldrev = $Page{revision};
if (GetParam('Preview', '')) { # Preview button was used
ReleaseLock();
if ($comment) {
if (defined $comment) {
BrowsePage($id, 0, RunMyMacros($comment)); # show macros in preview
} else {
DoEdit($id, $string, 1);
Expand All @@ -3651,7 +3651,7 @@ sub DoPost {
$string = $2;
}
my $generalwarning = 0;
if ($newAuthor and $oldtime ne $myoldtime and not $comment) {
if ($newAuthor and $oldtime ne $myoldtime and not defined $comment) {
if ($myoldtime) {
my ($ancestor) = GetTextAtTime($myoldtime);
if ($ancestor and $old ne $ancestor) {
Expand Down

0 comments on commit 4d8b028

Please sign in to comment.