jenkins-bot has submitted this change and it was merged.
Change subject: Improve input widget value sanitization
......................................................................
Improve input widget value sanitization
Objective:
* Prevent undefined and null from being converted to 'undefined' and
'null' when given to setValue by converting them to empty string instead
Changes:
ve.ui.InputWidget.js
* Move all sanitization to one place
* Improve sanitization by adding cases for undefined and null
Change-Id: I8817a8fcac271e560a9e49887c68a035293866d4
---
M modules/ve/ui/widgets/ve.ui.InputWidget.js
1 file changed, 7 insertions(+), 4 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/ui/widgets/ve.ui.InputWidget.js
b/modules/ve/ui/widgets/ve.ui.InputWidget.js
index 2e8dadd..3645a27 100644
--- a/modules/ve/ui/widgets/ve.ui.InputWidget.js
+++ b/modules/ve/ui/widgets/ve.ui.InputWidget.js
@@ -27,16 +27,17 @@
// Properties
this.$input = this.getInputElement( config );
- this.value = config.value === undefined ? '' : config.value;
+ this.value = '';
this.readonly = false;
// Events
this.$input.on( 'keydown mouseup cut paste change input select',
ve.bind( this.onEdit, this ) );
// Initialization
- this.$input.attr( 'name', config.name ).val( this.value );
+ this.$input.attr( 'name', config.name );
this.setReadOnly( config.readOnly );
this.$.addClass( 've-ui-inputWidget' ).append( this.$input );
+ this.setValue( config.value );
};
/* Inheritance */
@@ -118,7 +119,7 @@
this.value = value;
// Only update the DOM if we must
if ( domValue !== this.value ) {
- this.$input.val( this.value );
+ this.$input.val( value );
}
this.emit( 'change', this.value );
}
@@ -128,12 +129,14 @@
/**
* Sanitize incoming value.
*
+ * Ensures value is a string, and converts undefined and null to empty strings.
+ *
* @method
* @param {string} value Original value
* @returns {string} Sanitized value
*/
ve.ui.InputWidget.prototype.sanitizeValue = function ( value ) {
- return String( value );
+ return value === undefined || value === null ? '' : String( value );
};
/**
--
To view, visit https://gerrit.wikimedia.org/r/68031
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8817a8fcac271e560a9e49887c68a035293866d4
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits