mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-23 23:43:54 +00:00
Change param duplicate numbering to start with 2
… instead of 0. Conditionally add a dash in front as well to avoid confusing results like '1' + sequence number = '12'. Change-Id: I345704b00ba3812c4905f85e35cf21a6dfd05437
This commit is contained in:
parent
954211d8ba
commit
563a44ca72
|
@ -20,7 +20,7 @@ function Model() {
|
|||
this.format = null;
|
||||
|
||||
this.params = {};
|
||||
this.paramIdentifierCounter = 0;
|
||||
this.paramIdentifierCounter = 2;
|
||||
this.sourceCodeParameters = [];
|
||||
this.paramOrder = [];
|
||||
this.paramOrderChanged = false;
|
||||
|
@ -1114,6 +1114,9 @@ Model.prototype.getNewValidParameterKey = function ( key ) {
|
|||
var allParamNames = this.getAllParamNames();
|
||||
if ( this.params[ key ] || allParamNames.indexOf( key ) !== -1 ) {
|
||||
// Change the key to be something else
|
||||
if ( /\d$/.test( key ) ) {
|
||||
key += '-';
|
||||
}
|
||||
key += this.paramIdentifierCounter;
|
||||
this.paramIdentifierCounter++;
|
||||
return this.getNewValidParameterKey( key );
|
||||
|
|
|
@ -782,25 +782,25 @@ QUnit.test( 'Duplicate parameter names', function ( assert ) {
|
|||
model.addParam( 'color' );
|
||||
assert.deepEqual( model.getParams(), {
|
||||
color: { name: 'color' },
|
||||
color0: { name: 'color' }
|
||||
color2: { name: 'color' }
|
||||
} );
|
||||
assert.deepEqual( model.getTemplateParamOrder(), [ 'color', 'color0' ] );
|
||||
assert.deepEqual( model.getTemplateParamOrder(), [ 'color', 'color2' ] );
|
||||
|
||||
model.setParamProperty( 'color0', 'name', '1' );
|
||||
model.setParamProperty( 'color2', 'name', '1' );
|
||||
assert.deepEqual( model.getParams(), {
|
||||
color: { name: 'color' },
|
||||
color0: { deleted: true },
|
||||
color2: { deleted: true },
|
||||
1: { name: '1' }
|
||||
} );
|
||||
assert.deepEqual( model.getTemplateParamOrder(), [ 'color', '1' ] );
|
||||
model.setParamProperty( 'color', 'name', '1' );
|
||||
assert.deepEqual( model.getParams(), {
|
||||
color: { deleted: true },
|
||||
color0: { deleted: true },
|
||||
color2: { deleted: true },
|
||||
1: { name: '1' },
|
||||
11: { name: '1' }
|
||||
'1-3': { name: '1' }
|
||||
} );
|
||||
assert.deepEqual( model.getTemplateParamOrder(), [ '11', '1' ] );
|
||||
assert.deepEqual( model.getTemplateParamOrder(), [ '1-3', '1' ] );
|
||||
} );
|
||||
|
||||
QUnit.test( 'safesubst: hack with an unnamed parameter', function ( assert ) {
|
||||
|
|
Loading…
Reference in a new issue