mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-15 03:34:44 +00:00
Ignore bang magic word in table syntax when guessing parameters
Three-braces-and-a-bang can be a table starting construct in templates. This also fixes an overlooked bug in which the test wasn't checking array element key names. Bug: T157029 Change-Id: I69ed4fc9fe3bb126b7b39abea0f58ad56adf3885
This commit is contained in:
parent
af1bb1bffd
commit
75e54ae999
|
@ -904,7 +904,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] ) ) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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=""',
|
||||
[]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue