From 5ff5dbc7dc7a7439268631ccccd4f44fd18e50dd Mon Sep 17 00:00:00 2001 From: "This, that and the other" Date: Sun, 8 Jan 2017 20:15:48 +1100 Subject: [PATCH] Fix parsing of
 tags generated by extension tag hooks

When this part of BlockLevelPass::execute() encounters a block-level tag,
such as 
, one of $openMatch or $closeMatch will be truthy. Without this patch, $this->closeParagraph() is unconditionally called in this situation, which sets $this->inPre = false. If we're already inside a
 tag, this makes the parser think we're no longer in a 
environment, so it starts wrapping the 
 tag's content in 

tags as if it was processing regular content. We should only call $this->closeParagraph() in the case that (a) we are not inside a

 tag, or (b) the block-level tag that is being opened is
itself a 
 tag (in which case $preOpenMatch will be truthy, and
$this->inPre will have already been set to true).

This doesn't affect the parsing of 
 tags that are written in wikitext,
since their content isn't parsed. It only affects hooks and the like that
return 
 tags.

This doesn't solve the task T7718 that is mentioned in the code comment,
but if the testwiki test cases linked there are anything to go by, it
doesn't make the problem worse in any way.

This is required for Poem change I754f2e84f7d6efc0829765c82297f2de5f9ca149.

Change-Id: I469e633fc41d8ca73653c7e982c591092dcb1708
---
 includes/parser/BlockLevelPass.php |  8 ++++++--
 tests/parser/parserTests.txt       | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/includes/parser/BlockLevelPass.php b/includes/parser/BlockLevelPass.php
index 7f7891268f..7c92d76a20 100644
--- a/includes/parser/BlockLevelPass.php
+++ b/includes/parser/BlockLevelPass.php
@@ -304,8 +304,12 @@ class BlockLevelPass {
 
 				if ( $openMatch || $closeMatch ) {
 					$pendingPTag = false;
-					# @todo T7718: paragraph closed
-					$output .= $this->closeParagraph();
+					// Only close the paragraph if we're not inside a 
 tag, or if
+					// that 
 tag has just been opened
+					if ( !$this->inPre || $preOpenMatch ) {
+						// @todo T7718: paragraph closed
+						$output .= $this->closeParagraph();
+					}
 					if ( $preOpenMatch && !$preCloseMatch ) {
 						$this->inPre = true;
 					}
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index f98044b57c..889f040df7 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -18241,6 +18241,27 @@ this is a '''test'''
 

this is a test

!! end +!! test +Parser hook: horizontal rule inside extension tag that outputs
+!! wikitext
+
+Hello
+
+Goodbye +
+!! html/php +
+'
+Hello
+
+Goodbye +' +array ( +) +
+ +!! end + ### ### (see tests/parser/parserTestsParserHook.php for the extension) ### -- 2.20.1