Merge "Add missing validation for empty parameter names"

This commit is contained in:
jenkins-bot 2023-04-21 13:12:29 +00:00 committed by Gerrit Code Review
commit 849150c814
4 changed files with 10 additions and 0 deletions

View file

@ -47,6 +47,7 @@
"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-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-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.",

View file

@ -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-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-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-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.",

View file

@ -123,6 +123,10 @@ class TemplateDataValidator {
*/
private function validateParameters( stdClass $params ): ?Status {
foreach ( $params as $paramName => $param ) {
if ( trim( $paramName ) === '' ) {
return Status::newFatal( 'templatedata-invalid-unnamed-parameter' );
}
if ( !( $param instanceof stdClass ) ) {
return Status::newFatal( 'templatedata-invalid-type', "params.{$paramName}",
'object' );

View file

@ -87,6 +87,10 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase {
'input' => '{ "params": [] }',
'status' => '(templatedata-invalid-type: params, object)',
],
[
'input' => '{ "params": { "": {} } }',
'status' => '(templatedata-invalid-unnamed-parameter)',
],
[
'input' => '{ "params": { "a": [] } }',
'status' => '(templatedata-invalid-type: params.a, object)',