Explorar el Código

Added a check for the `results` key in AJAX responses

This should prevent users from running into unexpected errors when
they do not return an object with the `results` key containing an
array.

This closes https://github.com/select2/select2/issues/2950.
Kevin Brown hace 10 años
padre
commit
5b4e1eab42

+ 10 - 0
dist/js/select2.amd.full.js

@@ -2626,6 +2626,16 @@ define('select2/data/ajax',[
       $request.success(function (data) {
         var results = self.processResults(data, params);
 
+        if (console && console.error) {
+          // Check to make sure that the response included a `results` key.
+          if (!results || !results.results || !$.isArray(results.results)) {
+            console.error(
+              'Select2: The AJAX results did not return an array in the ' +
+              '`results` key of the response.'
+            );
+          }
+        }
+
         callback(results);
       });
 

+ 10 - 0
dist/js/select2.amd.js

@@ -2626,6 +2626,16 @@ define('select2/data/ajax',[
       $request.success(function (data) {
         var results = self.processResults(data, params);
 
+        if (console && console.error) {
+          // Check to make sure that the response included a `results` key.
+          if (!results || !results.results || !$.isArray(results.results)) {
+            console.error(
+              'Select2: The AJAX results did not return an array in the ' +
+              '`results` key of the response.'
+            );
+          }
+        }
+
         callback(results);
       });
 

+ 10 - 0
dist/js/select2.full.js

@@ -12161,6 +12161,16 @@ define('select2/data/ajax',[
       $request.success(function (data) {
         var results = self.processResults(data, params);
 
+        if (console && console.error) {
+          // Check to make sure that the response included a `results` key.
+          if (!results || !results.results || !$.isArray(results.results)) {
+            console.error(
+              'Select2: The AJAX results did not return an array in the ' +
+              '`results` key of the response.'
+            );
+          }
+        }
+
         callback(results);
       });
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
dist/js/select2.full.min.js


+ 10 - 0
dist/js/select2.js

@@ -3054,6 +3054,16 @@ define('select2/data/ajax',[
       $request.success(function (data) {
         var results = self.processResults(data, params);
 
+        if (console && console.error) {
+          // Check to make sure that the response included a `results` key.
+          if (!results || !results.results || !$.isArray(results.results)) {
+            console.error(
+              'Select2: The AJAX results did not return an array in the ' +
+              '`results` key of the response.'
+            );
+          }
+        }
+
         callback(results);
       });
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
dist/js/select2.min.js


+ 10 - 0
src/js/select2/data/ajax.js

@@ -46,6 +46,16 @@ define([
       $request.success(function (data) {
         var results = self.processResults(data, params);
 
+        if (console && console.error) {
+          // Check to make sure that the response included a `results` key.
+          if (!results || !results.results || !$.isArray(results.results)) {
+            console.error(
+              'Select2: The AJAX results did not return an array in the ' +
+              '`results` key of the response.'
+            );
+          }
+        }
+
         callback(results);
       });
 

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio