From 3060559d1d9cf603c02523c104e28bd0dd77efbe Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Fri, 3 Sep 2021 13:18:42 +0200 Subject: [PATCH] Fix parameter auto-detection picking up syntax elements See T290322 for a detailed description. Bug: T290322 Change-Id: Id9935482fb466e7a1f6e55f042b13fe5851412d0 --- includes/TemplateDataBlob.php | 2 +- .../ext.templateDataGenerator.data/SourceHandler.js | 2 +- tests/phpunit/TemplateDataBlobTest.php | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/includes/TemplateDataBlob.php b/includes/TemplateDataBlob.php index 8d51428b..21ac1eff 100644 --- a/includes/TemplateDataBlob.php +++ b/includes/TemplateDataBlob.php @@ -959,7 +959,7 @@ class TemplateDataBlob { $wikitext = preg_replace( '/.*?<\/nowiki\s*>/s', '', $wikitext ); // This regex matches the one in ext.TemplateDataGenerator.sourceHandler.js - preg_match_all( '/{{3,}([^#]*?)([<|]|}{3,})/m', $wikitext, $rawParams ); + preg_match_all( '/{{3,}([^\n#={|}]*?)([<|]|}{3,})/m', $wikitext, $rawParams ); $params = []; $normalizedParams = []; if ( isset( $rawParams[1] ) ) { diff --git a/modules/ext.templateDataGenerator.data/SourceHandler.js b/modules/ext.templateDataGenerator.data/SourceHandler.js index 5e3c1081..4fdccccb 100644 --- a/modules/ext.templateDataGenerator.data/SourceHandler.js +++ b/modules/ext.templateDataGenerator.data/SourceHandler.js @@ -172,7 +172,7 @@ SourceHandler.prototype.extractParametersFromTemplateCode = function ( templateC paramNames = [], normalizedParamNames = [], // This regex matches the one in TemplateDataBlob.php - paramExtractor = /{{3,}([^#]*?)([<|]|}{3,})/mg; + paramExtractor = /{{3,}([^\n#={|}]*?)([<|]|}{3,})/mg; // Strip everything in nowiki tags and HTML comments templateCode = templateCode.replace( //g, '' ) diff --git a/tests/phpunit/TemplateDataBlobTest.php b/tests/phpunit/TemplateDataBlobTest.php index 99705886..186953a3 100644 --- a/tests/phpunit/TemplateDataBlobTest.php +++ b/tests/phpunit/TemplateDataBlobTest.php @@ -1315,6 +1315,18 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase { '{{ {{{|safesubst:}}}#invoke:…|{{{1}}}|{{{ 1 }}}}}', [ '1' => [] ] ], + 'Characters impossible in parameter names' => [ + '{{test|a|b=c|d=e=f}} {{{a|b}}} {{{d=e}}}', + [ 'a' => [] ] + ], + 'Characters that are, while technically possible, almost certainly a mistake' => [ + "{{{a{a}}} {{{b}b}}} {{{c\nc}}}", + [] + ], + 'Table syntax escaped with {{!}}' => [ + '{{{!}}\n! This is table syntax\n{{!}}}', + [] + ], ]; }