From 4fff963520eb868459a8bbcc022f7223d8091340 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 14 Jan 2008 06:59:20 +0000 Subject: [PATCH] * Fixed loop detection in LST * Renamed some LST parser tests * Fixed caption behaviour .It should not generate
 when there
 are spaces at the start. Used recursiveTagParse() instead of parse(), to
 avoid generation of a limit report, among other things. * Refactored template
 loop check * Updated a couple of parser tests

---
 includes/Parser.php         | 25 ++++++++++++++-----------
 maintenance/parserTests.txt |  6 +++---
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/includes/Parser.php b/includes/Parser.php
index 06007e9e9f..226cc2ee20 100644
--- a/includes/Parser.php
+++ b/includes/Parser.php
@@ -3371,7 +3371,7 @@ class Parser
 					$wgContLang->findVariantLink($part1, $title);
 				}
 				# Do infinite loop check
-				if ( isset( $frame->loopCheckHash[$titleText] ) ) {
+				if ( !$frame->loopCheck( $title ) ) {
 					$found = true;
 					$text = "Template loop detected: [[$titleText]]";
 					wfDebug( __METHOD__.": template loop broken at '$titleText'\n" );
@@ -3440,8 +3440,6 @@ class Parser
 		if ( $isDOM ) {
 			# Clean up argument array
 			$newFrame = $frame->newChild( $args, $title );
-			# Add a new element to the templace loop detection hashtable
-			$newFrame->loopCheckHash[$titleText] = true;
 
 			if ( $titleText !== false && $newFrame->isEmpty() ) {
 				# Expansion is eligible for the empty-frame cache
@@ -4806,13 +4804,7 @@ class Parser
 				$label = '';
 			}
 
-			$pout = $this->parse( $label,
-				$this->mTitle,
-				$this->mOptions,
-				false, // Strip whitespace...?
-				false  // Don't clear state!
-			);
-			$html = $pout->getText();
+			$html = $this->recursiveTagParse( trim( $label ) );
 
 			$ig->add( $nt, $html );
 
@@ -5621,6 +5613,13 @@ class PPFrame {
 	function getArgument( $name ) {
 		return false;
 	}
+
+	/**
+	 * Returns true if the infinite loop check is OK, false if a loop is detected
+	 */
+	function loopCheck( $title ) {
+		return !isset( $this->loopCheckHash[$title->getPrefixedDBkey()] );
+	}
 }
 
 /**
@@ -5636,9 +5635,13 @@ class PPTemplateFrame extends PPFrame {
 		$this->numberedArgs = $numberedArgs;
 		$this->namedArgs = $namedArgs;
 		$this->title = $title;
+		$pdbk = $title ? $title->getPrefixedDBkey() : false;
 		$this->titleCache = $parent->titleCache;
-		$this->titleCache[] = $title ? $title->getPrefixedDBkey() : false;
+		$this->titleCache[] = $pdbk;
 		$this->loopCheckHash = /*clone*/ $parent->loopCheckHash;
+		if ( $pdbk !== false ) {
+			$this->loopCheckHash[$pdbk] = true;
+		}
 		$this->depth = $parent->depth + 1;
 		$this->numberedExpansionCache = $this->namedExpansionCache = array();
 	}
diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt
index 28f30231d7..c6af74fc39 100644
--- a/maintenance/parserTests.txt
+++ b/maintenance/parserTests.txt
@@ -2410,7 +2410,7 @@ Template infinite loop
 !! input
 {{loop1}}
 !! result
-

loop1 +

Template loop detected: Template:Loop1

!! end @@ -5972,8 +5972,8 @@ image4 |300px| centre
Image5.svg
-- 2.20.1