Skip to content

Commit 14279a0

Browse files
committed
Handle special characters in object ids
Slight performance hit as we are no longer using `qurySelectorAll`, but it handles the situation a bit more cleanly and prevent future issues with special characters. This closes select2#3157.
1 parent 1f62eb6 commit 14279a0

5 files changed

Lines changed: 12 additions & 6 deletions

File tree

dist/js/select2.full.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3136,7 +3136,9 @@ S2.define('select2/data/array',[
31363136
Utils.Extend(ArrayAdapter, SelectAdapter);
31373137

31383138
ArrayAdapter.prototype.select = function (data) {
3139-
var $option = this.$element.find('option[value="' + data.id + '"]');
3139+
var $option = this.$element.find('option').filter(function (i, elm) {
3140+
return elm.value == data.id.toString();
3141+
});
31403142

31413143
if ($option.length === 0) {
31423144
$option = this.option(data);

dist/js/select2.full.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3136,7 +3136,9 @@ S2.define('select2/data/array',[
31363136
Utils.Extend(ArrayAdapter, SelectAdapter);
31373137

31383138
ArrayAdapter.prototype.select = function (data) {
3139-
var $option = this.$element.find('option[value="' + data.id + '"]');
3139+
var $option = this.$element.find('option').filter(function (i, elm) {
3140+
return elm.value == data.id.toString();
3141+
});
31403142

31413143
if ($option.length === 0) {
31423144
$option = this.option(data);

dist/js/select2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/select2/data/array.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ define([
1414
Utils.Extend(ArrayAdapter, SelectAdapter);
1515

1616
ArrayAdapter.prototype.select = function (data) {
17-
var $option = this.$element.find('option[value="' + data.id + '"]');
17+
var $option = this.$element.find('option').filter(function (i, elm) {
18+
return elm.value == data.id.toString();
19+
});
1820

1921
if ($option.length === 0) {
2022
$option = this.option(data);

0 commit comments

Comments
 (0)