jenkins-bot has submitted this change and it was merged.

Change subject: Fix sanitizing of query value in media search
......................................................................


Fix sanitizing of query value in media search

Always use #getQueryValue which trims whitespace, so we
don't pass whitespace to the API.

Also rename some variables for clarity, and remove some
unused arguments.

Change-Id: I0d27f59488295bc1c398d0fd287e3e16a3f5aaec
---
M modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
1 file changed, 21 insertions(+), 12 deletions(-)

Approvals:
  Tchanders: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js 
b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
index 59cde6d..0679b29 100644
--- a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
@@ -26,7 +26,7 @@
 
        // Properties
        this.providers = {};
-       this.searchValue = '';
+       this.lastQueryValue = '';
        this.searchQueue = new ve.dm.MWMediaSearchQueue( {
                limit: this.constructor.static.limit,
                threshold: this.constructor.static.threshold
@@ -86,8 +86,7 @@
  * be updated.
  */
 ve.ui.MWMediaSearchWidget.prototype.afterResultsResize = function () {
-       var items = this.currentItemCache,
-               value = this.query.getValue();
+       var items = this.currentItemCache;
 
        if (
                items.length > 0 &&
@@ -98,7 +97,7 @@
        ) {
                this.resetRows();
                this.itemCache = {};
-               this.processQueueResults( items, value );
+               this.processQueueResults( items );
                if ( this.results.getItems().length > 0 ) {
                        this.lazyLoadResults();
                }
@@ -132,7 +131,7 @@
  */
 ve.ui.MWMediaSearchWidget.prototype.queryMediaQueue = function () {
        var search = this,
-               value = this.query.getValue();
+            value = this.getQueryValue();
 
        if ( value === '' ) {
                return;
@@ -145,7 +144,7 @@
        this.searchQueue.get( this.constructor.static.limit )
                .then( function ( items ) {
                        if ( items.length > 0 ) {
-                               search.processQueueResults( items, value );
+                               search.processQueueResults( items );
                                search.currentItemCache = 
search.currentItemCache.concat( items );
                        }
 
@@ -167,7 +166,7 @@
 ve.ui.MWMediaSearchWidget.prototype.processQueueResults = function ( items ) {
        var i, len, title,
                resultWidgets = [],
-               inputSearchQuery = this.query.getValue(),
+               inputSearchQuery = this.getQueryValue(),
                queueSearchQuery = this.searchQueue.getSearchQuery();
 
        if ( inputSearchQuery === '' || queueSearchQuery !== inputSearchQuery ) 
{
@@ -195,17 +194,26 @@
 };
 
 /**
+ * Get the sanitized query value from the input
+ *
+ * @return {string} Query value
+ */
+ve.ui.MWMediaSearchWidget.prototype.getQueryValue = function () {
+       return this.query.getValue().trim();
+};
+
+/**
  * Handle search value change
  *
  * @param {string} value New value
  */
-ve.ui.MWMediaSearchWidget.prototype.onQueryChange = function ( value ) {
-       var trimmed = value.trim();
+ve.ui.MWMediaSearchWidget.prototype.onQueryChange = function () {
+       // Get the sanitized query value
+       var queryValue = this.getQueryValue();
 
-       if ( trimmed === this.searchValue ) {
+       if ( queryValue === this.lastQueryValue ) {
                return;
        }
-       this.searchValue = trimmed;
 
        // Parent method
        ve.ui.MWMediaSearchWidget.super.prototype.onQueryChange.apply( this, 
arguments );
@@ -219,7 +227,8 @@
        this.layoutQueue = [];
 
        // Change resource queue query
-       this.searchQueue.setSearchQuery( this.searchValue );
+       this.searchQueue.setSearchQuery( queryValue );
+       this.lastQueryValue = queryValue;
 
        // Queue
        clearTimeout( this.queryTimeout );

-- 
To view, visit https://gerrit.wikimedia.org/r/315615
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0d27f59488295bc1c398d0fd287e3e16a3f5aaec
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Tchanders <thalia.e.c...@googlemail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to