From 93f0648a35545f6b4c54e24c695a122503d442f3 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Thu, 22 Feb 2024 16:02:19 -0500 Subject: [PATCH] [tests] Remove use of dynamic property Parser::$static_tag_buf There are only two test cases using the tag extension and it's no longer entirely clear what regression they were intended to prevent. In any case, we can use ParserOutput to maintain our parser state instead of the dynamic Parser::$static_tag_buf property. That's not a perfect solution -- T300979 says at some point in the future we won't guarantee parse order -- but it will work for now. Bug: T357838 Change-Id: Ia23049fc729c90a94fc16231ad89c199db5b7bc9 --- tests/parser/ParserTestParserHook.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/parser/ParserTestParserHook.php b/tests/parser/ParserTestParserHook.php index 27827471997..1a538d03543 100644 --- a/tests/parser/ParserTestParserHook.php +++ b/tests/parser/ParserTestParserHook.php @@ -54,21 +54,29 @@ class ParserTestParserHook { * @param array $argv * @param Parser $parser * @return string - * @suppress PhanUndeclaredProperty static_tag_buf is deliberately dynamic * @suppress SecurityCheck-XSS * @suppress UnusedSuppression */ public static function staticTagHook( $in, $argv, $parser ) { + $KEY = 'mw:tests:static-tag-hook'; + $po = $parser->getOutput(); if ( !count( $argv ) ) { - $parser->static_tag_buf = $in; + $po->appendExtensionData( $KEY, $in ); return ''; } elseif ( count( $argv ) === 1 && isset( $argv['action'] ) && $argv['action'] === 'flush' && $in === null ) { - // Clear the buffer, we probably don't need to - $tmp = $parser->static_tag_buf ?? ''; - $parser->static_tag_buf = null; - return $tmp; + // This pattern is deprecated, since the order of parsing will + // in the future not be guaranteed. A better approach is to + // collect/emit the buffered content in a post-processing pass + // over the document after parsing of the article and all contained + // fragments is completed and the fragments are merged. + // T357838, T300979 + $vals = $po->getExtensionData( $KEY ); + if ( $vals === null ) { + return ''; + } + return array_key_last( $vals ); } else { // wtf? return "\nCall this extension as string or as" . " , not in any other way.\n" . -- 2.11.4.GIT