From: jenkins-bot Date: Fri, 9 Feb 2018 22:34:46 +0000 (+0000) Subject: Merge "Fix ParserOutput::getText 'unwrap' flag for end-of-doc comment" X-Git-Tag: 1.31.0-rc.0~647 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=8fd5a99f4e261d37cd7237a1992b1bcf03a764d3;hp=232d76b2428278936d34a5e873e3b6e68bda7da1 Merge "Fix ParserOutput::getText 'unwrap' flag for end-of-doc comment" --- diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index e2efaff40f..346a151bee 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -301,10 +301,16 @@ class ParserOutput extends CacheTime { ] ); $startLen = strlen( $start ); $end = Html::closeElement( 'div' ); + $endPos = strrpos( $text, $end ); $endLen = strlen( $end ); - if ( substr( $text, 0, $startLen ) === $start && substr( $text, -$endLen ) === $end ) { - $text = substr( $text, $startLen, -$endLen ); + if ( substr( $text, 0, $startLen ) === $start && $endPos !== false + // if the closing div is followed by real content, bail out of unwrapping + && preg_match( '/^(?>\s*)*\s*$/s', substr( $text, $endPos + $endLen ) ) + ) { + $text = substr( $text, $startLen ); + $text = substr( $text, 0, $endPos - $startLen ) + . substr( $text, $endPos - $startLen + $endLen ); } } diff --git a/tests/phpunit/includes/parser/ParserOutputTest.php b/tests/phpunit/includes/parser/ParserOutputTest.php index efcc4e079e..1f3ee67433 100644 --- a/tests/phpunit/includes/parser/ParserOutputTest.php +++ b/tests/phpunit/includes/parser/ParserOutputTest.php @@ -349,6 +349,11 @@ EOF 'Unwrap without a mw-parser-output wrapper' => [ [ 'unwrap' => true ], [], '
Content
', '
Content
' ], + 'Unwrap with extra comment at end' => [ + [ 'unwrap' => true ], [], '

Test document.

+', '

Test document.

+' + ], ]; // phpcs:enable }