Merge "Fix parameter auto-detection picking up syntax elements"

This commit is contained in:
jenkins-bot 2021-10-06 23:27:08 +00:00 committed by Gerrit Code Review
commit da2077d5bc
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

@ -171,7 +171,7 @@ SourceHandler.prototype.extractParametersFromTemplateCode = function ( templateC
var 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

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