From 110a59200f54b7ef87c8a8253ee8082985aeb246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 24 Jan 2022 16:29:34 +0100 Subject: [PATCH] One more tweak for comparing comment ranges to transclusion/DOM ranges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we encounter a node that doesn't represent comment contents, e.g.: * a [reply] link we inserted (T297034#7641334) * an {{outdent}} template (see changed test case) …we should ignore it together with its descendants (like in Parser#nextInterestingLeafNode), instead of processing descendants and possibly detecting comment contents in them. Follow-up to 8de940b58784391669b92663db7cd2c8da50e88b, 72b9c2c6f5f77fcdc5c013620735f1c7367c8fe7. Bug: T297034 Change-Id: Ib2fa40c5fa389572b0e88ef558728fa06e3621b0 --- includes/CommentUtils.php | 37 ++++++++++++------- modules/utils.js | 35 +++++++++++------- .../en-big-parsoid-transcludedFrom.json | 2 +- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/includes/CommentUtils.php b/includes/CommentUtils.php index 113d2d9f2..131cb2542 100644 --- a/includes/CommentUtils.php +++ b/includes/CommentUtils.php @@ -635,32 +635,41 @@ class CommentUtils { $from = $boundary === 'end' ? self::getRangeLastNode( $a ) : self::getRangeFirstNode( $a ); $to = $boundary === 'end' ? self::getRangeLastNode( $b ) : self::getRangeFirstNode( $b ); - $skippingFrom = $boundary === 'end'; + $skipNode = null; + if ( $boundary === 'end' ) { + $skipNode = $from; + } + $foundContent = false; self::linearWalk( $from, static function ( string $event, Node $n ) use ( - $from, $to, $boundary, &$skippingFrom, &$foundContent + $from, $to, $boundary, &$skipNode, &$foundContent ) { if ( $n === $to && $event === ( $boundary === 'end' ? 'leave' : 'enter' ) ) { return true; } - if ( $skippingFrom ) { - $skippingFrom = !( $n === $from && $event === 'leave' ); + if ( $skipNode ) { + if ( $n === $skipNode && $event === 'leave' ) { + $skipNode = null; + } return; } - if ( - $event === 'enter' && - ( - !CommentUtils::isCommentSeparator( $n ) && - !CommentUtils::isRenderingTransparentNode( $n ) && - !CommentUtils::isOurGeneratedNode( $n ) && + if ( $event === 'enter' ) { + if ( + CommentUtils::isCommentSeparator( $n ) || + CommentUtils::isRenderingTransparentNode( $n ) || + CommentUtils::isOurGeneratedNode( $n ) + ) { + $skipNode = $n; + + } elseif ( CommentUtils::isCommentContent( $n ) - ) - ) { - $foundContent = true; - return true; + ) { + $foundContent = true; + return true; + } } } ); diff --git a/modules/utils.js b/modules/utils.js index 28b398543..4437cb8f1 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -561,7 +561,11 @@ function compareRangesAlmostEqualBoundaries( a, b, boundary ) { var from = boundary === 'end' ? getRangeLastNode( a ) : getRangeFirstNode( a ); var to = boundary === 'end' ? getRangeLastNode( b ) : getRangeFirstNode( b ); - var skippingFrom = boundary === 'end'; + var skipNode = null; + if ( boundary === 'end' ) { + skipNode = from; + } + var foundContent = false; linearWalk( from, @@ -569,22 +573,27 @@ function compareRangesAlmostEqualBoundaries( a, b, boundary ) { if ( n === to && event === ( boundary === 'end' ? 'leave' : 'enter' ) ) { return true; } - if ( skippingFrom ) { - skippingFrom = !( n === from && event === 'leave' ); + if ( skipNode ) { + if ( n === skipNode && event === 'leave' ) { + skipNode = null; + } return; } - if ( - event === 'enter' && - ( - !isCommentSeparator( n ) && - !isRenderingTransparentNode( n ) && - !isOurGeneratedNode( n ) && + if ( event === 'enter' ) { + if ( + isCommentSeparator( n ) || + isRenderingTransparentNode( n ) || + isOurGeneratedNode( n ) + ) { + skipNode = n; + + } else if ( isCommentContent( n ) - ) - ) { - foundContent = true; - return true; + ) { + foundContent = true; + return true; + } } } ); diff --git a/tests/cases/en-big-parsoid/en-big-parsoid-transcludedFrom.json b/tests/cases/en-big-parsoid/en-big-parsoid-transcludedFrom.json index 4b58dbebf..52e361560 100644 --- a/tests/cases/en-big-parsoid/en-big-parsoid-transcludedFrom.json +++ b/tests/cases/en-big-parsoid/en-big-parsoid-transcludedFrom.json @@ -49,7 +49,7 @@ "c-Xaosflux-2019-06-29T19:38:00.000Z-Bishonen-2019-06-29T19:30:00.000Z": false, "c-Suffusion_of_Yellow-2019-06-29T19:42:00.000Z-Bishonen-2019-06-29T19:30:00.000Z": false, "c-Suffusion_of_Yellow-2019-06-29T19:45:00.000Z-Suffusion_of_Yellow-2019-06-29T19:42:00.000Z": false, - "c-Suffusion_of_Yellow-2019-06-29T19:54:00.000Z-Missing_notification_icons_in_MonoBook": true, + "c-Suffusion_of_Yellow-2019-06-29T19:54:00.000Z-Missing_notification_icons_in_MonoBook": false, "c-Bishonen-2019-06-29T20:20:00.000Z-Suffusion_of_Yellow-2019-06-29T19:54:00.000Z": false, "c-Xaosflux-2019-06-26T03:14:00.000Z-Excessive_width_on_monobook": false, "c-Xaosflux-2019-06-26T03:41:00.000Z-Xaosflux-2019-06-26T03:14:00.000Z": false,