Changeset 1984


Ignore:
Timestamp:
01/15/09 05:49:06 (3 years ago)
Author:
SvenDowideit
Message:

Item727: data loss issue when missing anchor or location

Location:
trunk/CommentPlugin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CommentPlugin/data/System/CommentPlugin.txt

    r1952 r1984  
    249249|  Plugin Version: | 13 Jan 2009 %$VERSION% | 
    250250|  Change History: | | 
     251|  15 Jan 2008 | Foswikitask:Item727 - data loss issue when missing anchor or location | 
    251252|  13 Jan 2009 | Foswikitask:736 Make !CommentPlugin aware of CompareRevisionsAddOn bin script. | 
    252253|  16 Dec 2008 | Foswiki version | 
  • trunk/CommentPlugin/lib/Foswiki/Plugins/CommentPlugin/Comment.pm

    r1340 r1984  
    300300            $inpost = 1; 
    301301        } 
     302    } 
     303    #make sure the anchor or location exits 
     304    if (defined($location) and not($text =~ /(?<!location\=\")($location)/)) { 
     305        undef $location; 
     306    } 
     307    if (defined($anchor) and not($text =~ /^($anchor\s)/)) { 
     308        undef $anchor; 
    302309    } 
    303310 
  • trunk/CommentPlugin/test/unit/CommentPlugin/CommentPluginTests.pm

    r1340 r1984  
    6666            $sattrs .= $anchor; 
    6767        } 
    68         $sattrs .= '"'; 
     68        $sattrs .= '" '; 
    6969    } 
    7070 
     
    7272 
    7373    if ( $location ) { 
    74         $sattrs .= ' location="'.$location.'"'; 
     74        $sattrs .= ' location="'.$location.'" '; 
    7575    } 
    7676 
     
    7878    $sattrs .= 'type="'.$type.'" '; 
    7979 
    80     my $commentref = '%COMMENT{type="'.$type.'" refmark="here"}%'; 
     80    my $commentref = '%COMMENT{'.$sattrs.' refmark="here"}%'; 
    8181 
    8282    # Build the target topic 
    8383    my $sample = <<HERE; 
    8484TopOfTopic 
    85 %COMMENT{type="$type"}% 
     85%COMMENT{$sattrs}% 
    8686HERE 
    8787    if ($anchor ) { 
     
    205205    $this->assert_matches(qr/$comm/, $text, "$web.$topic: $text"); 
    206206 
     207#uncomment this to debug what the actual output looks like. 
     208#$this->assert_str_equals($sample, $text); 
     209 
    207210    my $refexpr; 
    208211    if ($anchor) { 
    209212        $refexpr = $anchor; 
    210213    } elsif ($location) { 
    211         $refexpr = "HereIsTheLocation"; 
     214        $refexpr = $location; 
    212215    } else { 
    213216        $refexpr = $commentref; 
     
    422425} 
    423426 
     427 
     428sub test_targetWebTopicAboveAnchor_Missing_Item727 { 
     429    my $this = shift; 
     430 
     431    my $sample = <<HERE; 
     432before 
     433%COMMENT{type="above" cols="100" target="%INCLUDINGTOPIC%#LatestComment"}% 
     434after 
     435HERE 
     436    $this->writeTopic($this->{test_web}, $this->{test_topic}, $sample); 
     437    my $pidx = 99; 
     438    my $html = 
     439      Foswiki::Plugins::CommentPlugin::Comment::_handleInput( 
     440          'remove="on"', 
     441          $this->{test_web}, 
     442          $this->{test_topic}, 
     443          \$pidx, 
     444          "The Message", 
     445          "", 
     446          "bottom"); 
     447    $this->assert_matches(qr/<input type="hidden" name="comment_remove" value="99"/, $html); 
     448 
     449    # Compose the query 
     450    my $comm = "This is the comment"; 
     451    my $query = new Unit::Request( 
     452                        { 
     453                         'comment_action' => 'save', 
     454                         'comment_type' => 'above', 
     455                         'comment' => $comm, 
     456                         'comment_anchor' => '#LatestComment', 
     457                        }); 
     458    $query->path_info("/$this->{test_web}/$this->{test_topic}"); 
     459 
     460    my $session = new Foswiki( $Foswiki::cfg{DefaultUserLoginName}, $query); 
     461    my $text = "Ignore this text"; 
     462 
     463    # invoke the save handler 
     464    $this->capture(\&Foswiki::UI::Save::save, $session ); 
     465 
     466    $text = Foswiki::Func::readTopicText($this->{test_web}, $this->{test_topic}); 
     467    # make sure it hasn't changed 
     468    $text =~ s/^%META.*?\n//gm; 
     469    $this->assert_str_equals(<<HERE, 
     470before 
     471 
     472 
     473This is the comment 
     474 
     475-- TemporaryCommentPluginTestsUsersWeb.WikiGuest - 15 Jan 2009 
     476%COMMENT{type="above" cols="100" target="%INCLUDINGTOPIC%#LatestComment"}% 
     477after 
     478HERE 
     479                             $text); 
     480} 
     481 
     482 
     483sub test_targetWebTopicBelowAnchor_Missing_Item727 { 
     484    my $this = shift; 
     485 
     486    my $sample = <<HERE; 
     487before 
     488%COMMENT{type="below" target="%INCLUDINGTOPIC%#LatestComment"}% 
     489after 
     490HERE 
     491    $this->writeTopic($this->{test_web}, $this->{test_topic}, $sample); 
     492    my $pidx = 99; 
     493    my $html = 
     494      Foswiki::Plugins::CommentPlugin::Comment::_handleInput( 
     495          'remove="on"', 
     496          $this->{test_web}, 
     497          $this->{test_topic}, 
     498          \$pidx, 
     499          "The Message", 
     500          "", 
     501          "bottom"); 
     502    $this->assert_matches(qr/<input type="hidden" name="comment_remove" value="99"/, $html); 
     503 
     504    # Compose the query 
     505    my $comm = "This is the comment"; 
     506    my $query = new Unit::Request( 
     507                        { 
     508                         'comment_action' => 'save', 
     509                         'comment_type' => 'below', 
     510                         'comment' => $comm, 
     511                         'comment_anchor' => '#LatestComment', 
     512 
     513                        }); 
     514    $query->path_info("/$this->{test_web}/$this->{test_topic}"); 
     515 
     516    my $session = new Foswiki( $Foswiki::cfg{DefaultUserLoginName}, $query); 
     517    my $text = "Ignore this text"; 
     518 
     519    # invoke the save handler 
     520    $this->capture(\&Foswiki::UI::Save::save, $session ); 
     521 
     522    $text = Foswiki::Func::readTopicText($this->{test_web}, $this->{test_topic}); 
     523    # make sure it hasn't changed 
     524    $text =~ s/^%META.*?\n//gm; 
     525    $this->assert_str_equals(<<HERE, 
     526before 
     527%COMMENT{type="below" target="%INCLUDINGTOPIC%#LatestComment"}% 
     528   * This is the comment -- TemporaryCommentPluginTestsUsersWeb.WikiGuest - 15 Jan 2009 
     529after 
     530HERE 
     531                             $text); 
     532} 
     533 
    4245341; 
Note: See TracChangeset for help on using the changeset viewer.