mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-30 18:44:15 +00:00
Merge "Add missing validation for empty parameter names"
This commit is contained in:
commit
849150c814
|
@ -47,6 +47,7 @@
|
||||||
"templatedata-exists-on-related-page": "Please note: there is already a template data block on the related page \"[[$1]]\".",
|
"templatedata-exists-on-related-page": "Please note: there is already a template data block on the related page \"[[$1]]\".",
|
||||||
"templatedata-helplink": "Information about template data",
|
"templatedata-helplink": "Information about template data",
|
||||||
"templatedata-helplink-target": "//www.mediawiki.org/wiki/Special:MyLanguage/Help:TemplateData",
|
"templatedata-helplink-target": "//www.mediawiki.org/wiki/Special:MyLanguage/Help:TemplateData",
|
||||||
|
"templatedata-invalid-unnamed-parameter": "Parameter names cannot be empty. To document unnamed parameters use their internal numbers \"1\", \"2\", and so on.",
|
||||||
"templatedata-invalid-duplicate-value": "Property \"$1\" (\"$3\") is a duplicate of \"$2\".",
|
"templatedata-invalid-duplicate-value": "Property \"$1\" (\"$3\") is a duplicate of \"$2\".",
|
||||||
"templatedata-invalid-empty-array": "Property \"$1\" must have at least one value in its array.",
|
"templatedata-invalid-empty-array": "Property \"$1\" must have at least one value in its array.",
|
||||||
"templatedata-invalid-format": "Property \"$1\" is expected to be \"inline\", \"block\", or a valid format string.",
|
"templatedata-invalid-format": "Property \"$1\" is expected to be \"inline\", \"block\", or a valid format string.",
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
"templatedata-exists-on-related-page": "A messaged that is displayed when there already is a templatedata string in a related page. $1: The page where templatedata already exists.",
|
"templatedata-exists-on-related-page": "A messaged that is displayed when there already is a templatedata string in a related page. $1: The page where templatedata already exists.",
|
||||||
"templatedata-helplink": "The label of the link to the TemplateData documentation, appearing above the editor field.",
|
"templatedata-helplink": "The label of the link to the TemplateData documentation, appearing above the editor field.",
|
||||||
"templatedata-helplink-target": "{{ignore}} The target of the link to the TemplateData documentation",
|
"templatedata-helplink-target": "{{ignore}} The target of the link to the TemplateData documentation",
|
||||||
|
"templatedata-invalid-unnamed-parameter": "Error message when a parameter name is empty.",
|
||||||
"templatedata-invalid-duplicate-value": "Displayed when an array that must only contain unique values contains a duplicate.\n* $1 - name of property containing the duplicate\n* $2 - name of property with first occurrence of value\n* $3 - the value being duplicated",
|
"templatedata-invalid-duplicate-value": "Displayed when an array that must only contain unique values contains a duplicate.\n* $1 - name of property containing the duplicate\n* $2 - name of property with first occurrence of value\n* $3 - the value being duplicated",
|
||||||
"templatedata-invalid-empty-array": "Error message when a property that must be non-empty is empty. Parameters:\n* $1 - property name (\"paramOrder\" or \"sets.{$setNr}.params\")",
|
"templatedata-invalid-empty-array": "Error message when a property that must be non-empty is empty. Parameters:\n* $1 - property name (\"paramOrder\" or \"sets.{$setNr}.params\")",
|
||||||
"templatedata-invalid-format": "{{Doc-important|Don't translate \"inline\" and \"block\".}}\n\nError message when format property gets an unexpected value.",
|
"templatedata-invalid-format": "{{Doc-important|Don't translate \"inline\" and \"block\".}}\n\nError message when format property gets an unexpected value.",
|
||||||
|
|
|
@ -123,6 +123,10 @@ class TemplateDataValidator {
|
||||||
*/
|
*/
|
||||||
private function validateParameters( stdClass $params ): ?Status {
|
private function validateParameters( stdClass $params ): ?Status {
|
||||||
foreach ( $params as $paramName => $param ) {
|
foreach ( $params as $paramName => $param ) {
|
||||||
|
if ( trim( $paramName ) === '' ) {
|
||||||
|
return Status::newFatal( 'templatedata-invalid-unnamed-parameter' );
|
||||||
|
}
|
||||||
|
|
||||||
if ( !( $param instanceof stdClass ) ) {
|
if ( !( $param instanceof stdClass ) ) {
|
||||||
return Status::newFatal( 'templatedata-invalid-type', "params.{$paramName}",
|
return Status::newFatal( 'templatedata-invalid-type', "params.{$paramName}",
|
||||||
'object' );
|
'object' );
|
||||||
|
|
|
@ -87,6 +87,10 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase {
|
||||||
'input' => '{ "params": [] }',
|
'input' => '{ "params": [] }',
|
||||||
'status' => '(templatedata-invalid-type: params, object)',
|
'status' => '(templatedata-invalid-type: params, object)',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'input' => '{ "params": { "": {} } }',
|
||||||
|
'status' => '(templatedata-invalid-unnamed-parameter)',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'input' => '{ "params": { "a": [] } }',
|
'input' => '{ "params": { "a": [] } }',
|
||||||
'status' => '(templatedata-invalid-type: params.a, object)',
|
'status' => '(templatedata-invalid-type: params.a, object)',
|
||||||
|
|
Loading…
Reference in a new issue