소스 검색

Fixed option text encoding

This fixes an issue when using a `<select>` where the elements were
created with XHTML-encoded characters to prevent any injection, as
they would be double-encoded and display incorrectly.

When using a `<select>`, we can assume that the data has already
been encoded because any XSS will have already run before we get to
it.  Because of this, we can just use `.text()` instead of `.html()`
to avoid any issues.

This also includes a test to ensure that this does not become an
issue in the future.

This closes https://github.com/select2/select2/issues/3115.
Kevin Brown 10 년 전
부모
커밋
0da15aa586
8개의 변경된 파일18개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 1
      dist/js/select2.amd.full.js
  2. 1 1
      dist/js/select2.amd.js
  3. 1 1
      dist/js/select2.full.js
  4. 0 0
      dist/js/select2.full.min.js
  5. 1 1
      dist/js/select2.js
  6. 0 0
      dist/js/select2.min.js
  7. 1 1
      src/js/select2/data/select.js
  8. 13 0
      tests/data/select-tests.js

+ 1 - 1
dist/js/select2.amd.full.js

@@ -2563,7 +2563,7 @@ define('select2/data/select',[
     if ($option.is('option')) {
       data = {
         id: $option.val(),
-        text: $option.html(),
+        text: $option.text(),
         disabled: $option.prop('disabled'),
         selected: $option.prop('selected'),
         title: $option.prop('title')

+ 1 - 1
dist/js/select2.amd.js

@@ -2563,7 +2563,7 @@ define('select2/data/select',[
     if ($option.is('option')) {
       data = {
         id: $option.val(),
-        text: $option.html(),
+        text: $option.text(),
         disabled: $option.prop('disabled'),
         selected: $option.prop('selected'),
         title: $option.prop('title')

+ 1 - 1
dist/js/select2.full.js

@@ -3002,7 +3002,7 @@ define('select2/data/select',[
     if ($option.is('option')) {
       data = {
         id: $option.val(),
-        text: $option.html(),
+        text: $option.text(),
         disabled: $option.prop('disabled'),
         selected: $option.prop('selected'),
         title: $option.prop('title')

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/js/select2.full.min.js


+ 1 - 1
dist/js/select2.js

@@ -3002,7 +3002,7 @@ define('select2/data/select',[
     if ($option.is('option')) {
       data = {
         id: $option.val(),
-        text: $option.html(),
+        text: $option.text(),
         disabled: $option.prop('disabled'),
         selected: $option.prop('selected'),
         title: $option.prop('title')

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/js/select2.min.js


+ 1 - 1
src/js/select2/data/select.js

@@ -205,7 +205,7 @@ define([
     if ($option.is('option')) {
       data = {
         id: $option.val(),
-        text: $option.html(),
+        text: $option.text(),
         disabled: $option.prop('disabled'),
         selected: $option.prop('selected'),
         title: $option.prop('title')

+ 13 - 0
tests/data/select-tests.js

@@ -439,3 +439,16 @@ test('multiple options with the same value are returned', function (assert) {
     );
   });
 });
+
+test('data objects use the text of the option', function (assert) {
+  var $select = $('#qunit-fixture .duplicates');
+
+  var data = new SelectData($select, options);
+
+  var $option = $('<option>&amp;</option>');
+
+  var item = data.item($option);
+
+  assert.equal(item.id, '&');
+  assert.equal(item.text, '&');
+});

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