소스 검색

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 11 년 전
부모
커밋
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);
       });
 

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.