From 8b426c7e5c223d6034c3d2ebd06917b781e4b9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Tue, 11 Jan 2022 22:58:57 +0100 Subject: [PATCH] Fix placeholder headings causing exceptions in getTranscludedFrom() Follow-up to 8de940b58784391669b92663db7cd2c8da50e88b. Change-Id: Iddf045105fac6ab8cdaa933fd2abcf6dbbd37d42 --- includes/CommentUtils.php | 6 ++++-- includes/HeadingItem.php | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/includes/CommentUtils.php b/includes/CommentUtils.php index 0bb3a39da..b7bce0fad 100644 --- a/includes/CommentUtils.php +++ b/includes/CommentUtils.php @@ -518,10 +518,11 @@ class CommentUtils { } /** - * @param ImmutableRange $range + * @param ImmutableRange $range (must not be collapsed) * @return Node */ public static function getRangeFirstNode( ImmutableRange $range ): Node { + Assert::precondition( !$range->collapsed, 'Range is not collapsed' ); // PHP bug: childNodes can be null return $range->startContainer->childNodes && $range->startContainer->childNodes->length ? $range->startContainer->childNodes[ $range->startOffset ] : @@ -529,10 +530,11 @@ class CommentUtils { } /** - * @param ImmutableRange $range + * @param ImmutableRange $range (must not be collapsed) * @return Node */ public static function getRangeLastNode( ImmutableRange $range ): Node { + Assert::precondition( !$range->collapsed, 'Range is not collapsed' ); // PHP bug: childNodes can be null return $range->endContainer->childNodes && $range->endContainer->childNodes->length ? $range->endContainer->childNodes[ $range->endOffset - 1 ] : diff --git a/includes/HeadingItem.php b/includes/HeadingItem.php index 1da1a6df5..b97a4c17c 100644 --- a/includes/HeadingItem.php +++ b/includes/HeadingItem.php @@ -97,4 +97,15 @@ class HeadingItem extends ThreadItem { $this->getName() !== 'h-' ); } + + /** + * @inheritDoc + */ + public function getTranscludedFrom() { + // Placeholder headings break the usual logic, because their ranges are collapsed + if ( $this->isPlaceholderHeading() ) { + return false; + } + return parent::getTranscludedFrom(); + } }