Merge "CommentUtils: Fix isSingleCommentSignedBy() with empty heading"

This commit is contained in:
jenkins-bot 2022-03-21 23:45:53 +00:00 committed by Gerrit Code Review
commit d91fe7aad0
2 changed files with 16 additions and 6 deletions

View file

@ -724,13 +724,19 @@ class CommentUtils {
$items = $itemSet->getThreadItems();
if ( $items ) {
$lastItem = end( $items );
// Check that we've detected a comment first, not just headings (T304377)
if ( !( $lastItem instanceof CommentItem && $lastItem->getAuthor() === $author ) ) {
return false;
}
// Range covering all of the detected items (to account for a heading, and for multiple
// signatures resulting in multiple comments)
$commentsRange = new ImmutableRange(
$items[0]->getRange()->startContainer,
$items[0]->getRange()->startOffset,
end( $items )->getRange()->endContainer,
end( $items )->getRange()->endOffset
$lastItem->getRange()->endContainer,
$lastItem->getRange()->endOffset
);
$bodyRange = new ImmutableRange(
$rootNode, 0, $rootNode, count( $rootNode->childNodes )
@ -738,12 +744,9 @@ class CommentUtils {
if ( self::compareRanges( $commentsRange, $bodyRange ) === 'equal' ) {
// New comment includes a signature in the proper place
$lastComment = end( $items );
if ( $lastComment instanceof CommentItem && $lastComment->getAuthor() === $author ) {
return true;
}
}
}
return false;
}

View file

@ -13,6 +13,13 @@
"html": "<h2><span class=\"mw-headline\" id=\"Foo\">Foo</span></h2>\n<p>bar\n</p>",
"expected": false
},
{
"msg": "Simple message [with empty heading]",
"title": "Talk:A",
"user": "X",
"html": "<h2><span class=\"mw-headline\" id=\"\"></span></h2>\n<p>bar\n</p>",
"expected": false
},
{
"msg": "Simple message [indented]",
"title": "Talk:A",