mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-12-18 02:40:38 +00:00
Fix parameter auto-detection picking up syntax elements
See T290322 for a detailed description. Bug: T290322 Change-Id: Id9935482fb466e7a1f6e55f042b13fe5851412d0
This commit is contained in:
parent
a7e1d60c64
commit
3060559d1d
|
@ -959,7 +959,7 @@ class TemplateDataBlob {
|
||||||
$wikitext = preg_replace( '/<nowiki\s*>.*?<\/nowiki\s*>/s', '', $wikitext );
|
$wikitext = preg_replace( '/<nowiki\s*>.*?<\/nowiki\s*>/s', '', $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,}([^#]*?)([<|]|}{3,})/m', $wikitext, $rawParams );
|
preg_match_all( '/{{3,}([^\n#={|}]*?)([<|]|}{3,})/m', $wikitext, $rawParams );
|
||||||
$params = [];
|
$params = [];
|
||||||
$normalizedParams = [];
|
$normalizedParams = [];
|
||||||
if ( isset( $rawParams[1] ) ) {
|
if ( isset( $rawParams[1] ) ) {
|
||||||
|
|
|
@ -172,7 +172,7 @@ SourceHandler.prototype.extractParametersFromTemplateCode = function ( templateC
|
||||||
paramNames = [],
|
paramNames = [],
|
||||||
normalizedParamNames = [],
|
normalizedParamNames = [],
|
||||||
// This regex matches the one in TemplateDataBlob.php
|
// 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
|
// Strip everything in nowiki tags and HTML comments
|
||||||
templateCode = templateCode.replace( /<!--[\s\S]*?-->/g, '' )
|
templateCode = templateCode.replace( /<!--[\s\S]*?-->/g, '' )
|
||||||
|
|
|
@ -1315,6 +1315,18 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase {
|
||||||
'{{ {{{|safesubst:}}}#invoke:…|{{{1}}}|{{{ 1 }}}}}',
|
'{{ {{{|safesubst:}}}#invoke:…|{{{1}}}|{{{ 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{{!}}}',
|
||||||
|
[]
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue