diff --git a/includes/TemplateDataBlob.php b/includes/TemplateDataBlob.php index 675fe797..2e8afa1f 100644 --- a/includes/TemplateDataBlob.php +++ b/includes/TemplateDataBlob.php @@ -922,7 +922,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,}([^#]*?)[<|}]/m', $wikitext, $rawParams ); $params = []; $normalizedParams = []; if ( isset( $rawParams[1] ) ) { diff --git a/modules/ext.templateDataGenerator.sourceHandler.js b/modules/ext.templateDataGenerator.sourceHandler.js index 93312ba1..f31e897b 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,}([^#]*?)[<|}]/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 4ff29f06..3271acf0 100644 --- a/tests/phpunit/TemplateDataBlobTest.php +++ b/tests/phpunit/TemplateDataBlobTest.php @@ -1214,27 +1214,34 @@ class TemplateDataBlobTest extends MediaWikiTestCase { public function provideGetRawParams() { return [ - [ + 'No params' => [ 'Lorem ipsum {{tpl}}.', [] ], - [ - 'Lorem {{{name}}} ipsum', - [ 'name' => [] ] + 'Two plain params' => [ + 'Lorem {{{name}}} ipsum {{{surname}}}', + [ 'name' => [], 'surname' => [] ] ], - [ + 'Param with multiple casing and default value' => [ 'Lorem {{{name|{{{Name|Default name}}}}}} ipsum', [ 'name' => [] ] ], - [ + 'Param name contains comment' => [ 'Lorem {{{name}}} ipsum', [ 'name' => [] ] ], - [ - // Check for letter-case and underscore-space normalization. + 'Letter-case and underscore-space normalization' => [ 'Lorem {{{First name|{{{first_name}}}}}} ipsum {{{first-Name}}}', [ 'First name' => [] ] ], + 'Dynamic param name' => [ + '{{{{{#if:{{{nominee|}}}|nominee|candidate}}|}}}', + [ 'nominee' => [] ] + ], + 'More complicated dynamic param name' => [ + '{{{party{{#if:{{{party_election||}}}|_election||}}|}}}', + [ 'party_election' => [] ] + ] ]; } }