mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-23 23:43:54 +00:00
Prevent leading hash from starting param names when guessing
Parameter names can be constructed with parser functions, so we should not include these as raw parameter names. There might be more characters to add here. Bug: T203605 Change-Id: If57a9ed7edf1e881cd121d9a1bcb2e7455c04ec9
This commit is contained in:
parent
e01b0bcea7
commit
79e5347d90
|
@ -922,7 +922,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,}([^#]*?)[<|}]/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,}([^#]*?)[<|}]/mg;
|
||||
|
||||
while ( ( matches = paramExtractor.exec( templateCode ) ) !== null ) {
|
||||
// This normalization process is repeated in PHP in TemplateDataBlob.php
|
||||
|
|
|
@ -1214,27 +1214,34 @@ class TemplateDataBlobTest extends MediaWikiTestCase {
|
|||
|
||||
public function provideGetRawParams() {
|
||||
return [
|
||||
[
|
||||
'No params' => [
|
||||
'Lorem ipsum {{tpl}}.',
|
||||
[]
|
||||
],
|
||||
[
|
||||
'Lorem {{{name}}} ipsum',
|
||||
[ 'name' => [] ]
|
||||
'Two plain params' => [
|
||||
'Lorem {{{name}}} ipsum {{{surname}}}',
|
||||
[ 'name' => [], 'surname' => [] ]
|
||||
],
|
||||
[
|
||||
'Param with multiple casing and default value' => [
|
||||
'Lorem {{{name|{{{Name|Default name}}}}}} ipsum',
|
||||
[ 'name' => [] ]
|
||||
],
|
||||
[
|
||||
'Param name contains comment' => [
|
||||
'Lorem {{{name<!-- comment -->}}} ipsum',
|
||||
[ 'name' => [] ]
|
||||
],
|
||||
[
|
||||
// Check for letter-case and underscore-space normalization.
|
||||
'Letter-case and underscore-space normalization' => [
|
||||
'Lorem {{{First name|{{{first_name}}}}}} ipsum {{{first-Name}}}',
|
||||
[ 'First name' => [] ]
|
||||
],
|
||||
'Dynamic param name' => [
|
||||
'{{{{{#if:{{{nominee|}}}|nominee|candidate}}|}}}',
|
||||
[ 'nominee' => [] ]
|
||||
],
|
||||
'More complicated dynamic param name' => [
|
||||
'{{{party{{#if:{{{party_election||}}}|_election||}}|}}}',
|
||||
[ 'party_election' => [] ]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue