Fix parameter auto-detection picking up syntax elements

See T290322 for a detailed description.

Bug: T290322
Change-Id: Id9935482fb466e7a1f6e55f042b13fe5851412d0
This commit is contained in:
Thiemo Kreuz 2021-09-03 13:18:42 +02:00
parent a7e1d60c64
commit 3060559d1d
3 changed files with 14 additions and 2 deletions

View file

@ -959,7 +959,7 @@ class TemplateDataBlob {
$wikitext = preg_replace( '/<nowiki\s*>.*?<\/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] ) ) {

View file

@ -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( /<!--[\s\S]*?-->/g, '' )

View file

@ -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{{!}}}',
[]
],
];
}