Преглед на файлове

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 преди 10 години
родител
ревизия
5b4e1eab42
променени са 7 файла, в които са добавени 50 реда и са изтрити 0 реда
  1. 10 0
      dist/js/select2.amd.full.js
  2. 10 0
      dist/js/select2.amd.js
  3. 10 0
      dist/js/select2.full.js
  4. 0 0
      dist/js/select2.full.min.js
  5. 10 0
      dist/js/select2.js
  6. 0 0
      dist/js/select2.min.js
  7. 10 0
      src/js/select2/data/ajax.js

+ 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);
       });
 

Файловите разлики са ограничени, защото са твърде много
+ 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);
       });
 

Файловите разлики са ограничени, защото са твърде много
+ 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);
       });
 

Някои файлове не бяха показани, защото твърде много файлове са промени