Fix ParserOutput::getText 'unwrap' flag for end-of-doc comment
[lhc/web/wiklou.git] / includes / parser / ParserOutput.php
index e2efaff..346a151 100644 (file)
@@ -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 );
                        }
                }