diff --git a/includes/TemplateDataBlob.php b/includes/TemplateDataBlob.php index 5ebcfa95..f04d20fd 100644 --- a/includes/TemplateDataBlob.php +++ b/includes/TemplateDataBlob.php @@ -905,7 +905,7 @@ class TemplateDataBlob { */ public static function getRawParams( $wikitext ) { // This regex matches the one in ext.TemplateDataGenerator.sourceHandler.js - preg_match_all( '/{{3,}([^#]*?)[<|}]/m', $wikitext, $rawParams ); + preg_match_all( '/{{3,}([^#]*?)([<|]|}{3,})/m', $wikitext, $rawParams ); $params = []; $normalizedParams = []; if ( isset( $rawParams[1] ) ) { diff --git a/modules/ext.templateDataGenerator.sourceHandler.js b/modules/ext.templateDataGenerator.sourceHandler.js index c0301a62..dc585a2b 100644 --- a/modules/ext.templateDataGenerator.sourceHandler.js +++ b/modules/ext.templateDataGenerator.sourceHandler.js @@ -167,7 +167,7 @@ mw.TemplateData.SourceHandler.prototype.extractParametersFromTemplateCode = func paramNames = [], normalizedParamNames = [], // This regex matches the one in TemplateDataBlob.php - paramExtractor = /{{3,}([^#]*?)[<|}]/mg; + paramExtractor = /{{3,}([^#]*?)([<|]|}{3,})/mg; while ( ( matches = paramExtractor.exec( templateCode ) ) !== null ) { // This normalization process is repeated in PHP in TemplateDataBlob.php diff --git a/tests/phpunit/TemplateDataBlobTest.php b/tests/phpunit/TemplateDataBlobTest.php index f57cfc0e..745bb916 100644 --- a/tests/phpunit/TemplateDataBlobTest.php +++ b/tests/phpunit/TemplateDataBlobTest.php @@ -1214,7 +1214,8 @@ class TemplateDataBlobTest extends MediaWikiTestCase { * @dataProvider provideGetRawParams */ public function testGetRawParams( $inputWikitext, $expectedParams ) { - $this->assertArrayEquals( $expectedParams, TemplateDataBlob::getRawParams( $inputWikitext ) ); + $params = TemplateDataBlob::getRawParams( $inputWikitext ); + $this->assertArrayEquals( $expectedParams, $params, true, true ); } public function provideGetRawParams() { @@ -1246,7 +1247,15 @@ class TemplateDataBlobTest extends MediaWikiTestCase { 'More complicated dynamic param name' => [ '{{{party{{#if:{{{party_election||}}}|_election||}}|}}}', [ 'party_election' => [] ] - ] + ], + 'Bang in a param name' => [ + '{{{!}}} {{{foo!}}}', + [ '!' => [], 'foo!' => [] ] + ], + 'Bang as a magic word in a table construct' => [ + '{{{!}} class=""', + [] + ], ]; } }