Merge "Ignore bang magic word in table syntax when guessing parameters"

This commit is contained in:
jenkins-bot 2018-12-10 23:55:08 +00:00 committed by Gerrit Code Review
commit 4221945fc9
3 changed files with 13 additions and 4 deletions

View file

@ -905,7 +905,7 @@ class TemplateDataBlob {
*/ */
public static function getRawParams( $wikitext ) { public static function getRawParams( $wikitext ) {
// This regex matches the one in ext.TemplateDataGenerator.sourceHandler.js // 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 = []; $params = [];
$normalizedParams = []; $normalizedParams = [];
if ( isset( $rawParams[1] ) ) { if ( isset( $rawParams[1] ) ) {

View file

@ -167,7 +167,7 @@ mw.TemplateData.SourceHandler.prototype.extractParametersFromTemplateCode = func
paramNames = [], paramNames = [],
normalizedParamNames = [], normalizedParamNames = [],
// This regex matches the one in TemplateDataBlob.php // This regex matches the one in TemplateDataBlob.php
paramExtractor = /{{3,}([^#]*?)[<|}]/mg; paramExtractor = /{{3,}([^#]*?)([<|]|}{3,})/mg;
while ( ( matches = paramExtractor.exec( templateCode ) ) !== null ) { while ( ( matches = paramExtractor.exec( templateCode ) ) !== null ) {
// This normalization process is repeated in PHP in TemplateDataBlob.php // This normalization process is repeated in PHP in TemplateDataBlob.php

View file

@ -1214,7 +1214,8 @@ class TemplateDataBlobTest extends MediaWikiTestCase {
* @dataProvider provideGetRawParams * @dataProvider provideGetRawParams
*/ */
public function testGetRawParams( $inputWikitext, $expectedParams ) { public function testGetRawParams( $inputWikitext, $expectedParams ) {
$this->assertArrayEquals( $expectedParams, TemplateDataBlob::getRawParams( $inputWikitext ) ); $params = TemplateDataBlob::getRawParams( $inputWikitext );
$this->assertArrayEquals( $expectedParams, $params, true, true );
} }
public function provideGetRawParams() { public function provideGetRawParams() {
@ -1246,7 +1247,15 @@ class TemplateDataBlobTest extends MediaWikiTestCase {
'More complicated dynamic param name' => [ 'More complicated dynamic param name' => [
'{{{party{{#if:{{{party_election||}}}|_election||}}|}}}', '{{{party{{#if:{{{party_election||}}}|_election||}}|}}}',
[ 'party_election' => [] ] [ 'party_election' => [] ]
] ],
'Bang in a param name' => [
'{{{!}}} {{{foo!}}}',
[ '!' => [], 'foo!' => [] ]
],
'Bang as a magic word in a table construct' => [
'{{{!}} class=""',
[]
],
]; ];
} }
} }