Merge "Fix all spec methods to not crash on unknown parameters"

This commit is contained in:
jenkins-bot 2021-06-29 09:41:07 +00:00 committed by Gerrit Code Review
commit d588a736c2
2 changed files with 32 additions and 26 deletions

View file

@ -187,8 +187,8 @@ ve.dm.MWTemplateSpecModel.prototype.isParameterAlias = function ( name ) {
* @return {string} Parameter label
*/
ve.dm.MWTemplateSpecModel.prototype.getParameterLabel = function ( name, lang ) {
var primaryName = this.getPrimaryParameterName( name );
return this.constructor.static.getLocalValue( this.params[ primaryName ].label || name, lang );
var param = this.params[ this.getPrimaryParameterName( name ) ];
return this.constructor.static.getLocalValue( param && param.label || name, lang );
};
/**
@ -199,8 +199,8 @@ ve.dm.MWTemplateSpecModel.prototype.getParameterLabel = function ( name, lang )
* @return {string|null} Parameter description
*/
ve.dm.MWTemplateSpecModel.prototype.getParameterDescription = function ( name, lang ) {
name = this.getPrimaryParameterName( name );
return this.constructor.static.getLocalValue( this.params[ name ].description || null, lang );
var param = this.params[ this.getPrimaryParameterName( name ) ];
return this.constructor.static.getLocalValue( param && param.description || null, lang );
};
/**
@ -210,8 +210,8 @@ ve.dm.MWTemplateSpecModel.prototype.getParameterDescription = function ( name, l
* @return {string[]} Parameter suggested values
*/
ve.dm.MWTemplateSpecModel.prototype.getParameterSuggestedValues = function ( name ) {
name = this.getPrimaryParameterName( name );
return this.params[ name ].suggestedvalues || [];
var param = this.params[ this.getPrimaryParameterName( name ) ];
return param && param.suggestedvalues || [];
};
/**
@ -221,8 +221,7 @@ ve.dm.MWTemplateSpecModel.prototype.getParameterSuggestedValues = function ( nam
* @return {string} Default parameter value
*/
ve.dm.MWTemplateSpecModel.prototype.getParameterDefaultValue = function ( name ) {
name = this.getPrimaryParameterName( name );
var param = this.params[ name ];
var param = this.params[ this.getPrimaryParameterName( name ) ];
return param && param.default || '';
};
@ -234,8 +233,8 @@ ve.dm.MWTemplateSpecModel.prototype.getParameterDefaultValue = function ( name )
* @return {string|null}
*/
ve.dm.MWTemplateSpecModel.prototype.getParameterExampleValue = function ( name, lang ) {
name = this.getPrimaryParameterName( name );
return this.constructor.static.getLocalValue( this.params[ name ].example || null, lang );
var param = this.params[ this.getPrimaryParameterName( name ) ];
return this.constructor.static.getLocalValue( param && param.example || null, lang );
};
/**
@ -245,8 +244,7 @@ ve.dm.MWTemplateSpecModel.prototype.getParameterExampleValue = function ( name,
* @return {string} Auto-value for the parameter
*/
ve.dm.MWTemplateSpecModel.prototype.getParameterAutoValue = function ( name ) {
name = this.getPrimaryParameterName( name );
var param = this.params[ name ];
var param = this.params[ this.getPrimaryParameterName( name ) ];
return param && param.autovalue || '';
};
@ -257,8 +255,8 @@ ve.dm.MWTemplateSpecModel.prototype.getParameterAutoValue = function ( name ) {
* @return {string} Parameter type
*/
ve.dm.MWTemplateSpecModel.prototype.getParameterType = function ( name ) {
name = this.getPrimaryParameterName( name );
return this.params[ name ].type || 'string';
var param = this.params[ this.getPrimaryParameterName( name ) ];
return param && param.type || 'string';
};
/**
@ -268,8 +266,8 @@ ve.dm.MWTemplateSpecModel.prototype.getParameterType = function ( name ) {
* @return {string[]} Alternate parameter names
*/
ve.dm.MWTemplateSpecModel.prototype.getParameterAliases = function ( name ) {
name = this.getPrimaryParameterName( name );
return this.params[ name ].aliases || [];
var param = this.params[ this.getPrimaryParameterName( name ) ];
return param && param.aliases || [];
};
/**
@ -291,8 +289,8 @@ ve.dm.MWTemplateSpecModel.prototype.getPrimaryParameterName = function ( name )
* @return {boolean} Parameter is required
*/
ve.dm.MWTemplateSpecModel.prototype.isParameterRequired = function ( name ) {
name = this.getPrimaryParameterName( name );
return !!this.params[ name ].required;
var param = this.params[ this.getPrimaryParameterName( name ) ];
return !!( param && param.required );
};
/**
@ -302,8 +300,8 @@ ve.dm.MWTemplateSpecModel.prototype.isParameterRequired = function ( name ) {
* @return {boolean} Parameter is suggested
*/
ve.dm.MWTemplateSpecModel.prototype.isParameterSuggested = function ( name ) {
name = this.getPrimaryParameterName( name );
return !!this.params[ name ].suggested;
var param = this.params[ this.getPrimaryParameterName( name ) ];
return !!( param && param.suggested );
};
/**
@ -313,9 +311,8 @@ ve.dm.MWTemplateSpecModel.prototype.isParameterSuggested = function ( name ) {
* @return {boolean} Parameter is deprecated
*/
ve.dm.MWTemplateSpecModel.prototype.isParameterDeprecated = function ( name ) {
name = this.getPrimaryParameterName( name );
return typeof this.params[ name ].deprecated === 'string' ||
!!this.params[ name ].deprecated;
var param = this.params[ this.getPrimaryParameterName( name ) ];
return !!( param && ( param.deprecated || typeof param.deprecated === 'string' ) );
};
/**
@ -326,9 +323,8 @@ ve.dm.MWTemplateSpecModel.prototype.isParameterDeprecated = function ( name ) {
* deprecated or no description has been specified
*/
ve.dm.MWTemplateSpecModel.prototype.getParameterDeprecationDescription = function ( name ) {
name = this.getPrimaryParameterName( name );
return typeof this.params[ name ].deprecated === 'string' ?
this.params[ name ].deprecated : '';
var param = this.params[ this.getPrimaryParameterName( name ) ];
return param && typeof param.deprecated === 'string' ? param.deprecated : '';
};
/**

View file

@ -32,9 +32,19 @@
assert.deepEqual( spec.getCanonicalParameterOrder(), [], 'getCanonicalParameterOrder' );
assert.strictEqual( spec.isKnownParameterOrAlias( 'unknown' ), false, 'isKnownParameterOrAlias' );
assert.strictEqual( spec.isParameterAlias( 'unknown' ), false, 'isParameterAlias' );
assert.strictEqual( spec.getParameterLabel( 'unknown' ), 'unknown', 'getParameterLabel' );
assert.strictEqual( spec.getParameterDescription( 'unknown' ), null, 'getParameterDescription' );
assert.deepEqual( spec.getParameterSuggestedValues( 'unknown' ), [], 'getParameterSuggestedValues' );
assert.strictEqual( spec.getParameterDefaultValue( 'unknown' ), '', 'getParameterDefaultValue' );
assert.strictEqual( spec.getParameterExampleValue( 'unknown' ), null, 'getParameterExampleValue' );
assert.strictEqual( spec.getParameterAutoValue( 'unknown' ), '', 'getParameterAutoValue' );
assert.strictEqual( spec.getParameterType( 'unknown' ), 'string', 'getParameterType' );
assert.deepEqual( spec.getParameterAliases( 'unknown' ), [], 'getParameterAliases' );
assert.strictEqual( spec.getPrimaryParameterName( 'unknown' ), 'unknown', 'getPrimaryParameterName' );
assert.strictEqual( spec.isParameterRequired( 'unknown' ), false, 'isParameterRequired' );
assert.strictEqual( spec.isParameterSuggested( 'unknown' ), false, 'isParameterSuggested' );
assert.strictEqual( spec.isParameterDeprecated( 'unknown' ), false, 'isParameterDeprecated' );
assert.strictEqual( spec.getParameterDeprecationDescription( 'unknown' ), '', 'getParameterDeprecationDescription' );
assert.deepEqual( spec.getParameterNames(), [], 'getParameterNames' );
assert.deepEqual( spec.getParameterSets(), [], 'getParameterSets' );
assert.deepEqual( spec.getMaps(), {}, 'getMaps' );