Skip to content

Commit

Permalink
spec alignment: HTML optgroup elements cannot be nested, so the data …
Browse files Browse the repository at this point in the history
…provided to a select2 constructor should not contain multiple levels of child nesting; limit normalizeItem recursion to depth one as a result
  • Loading branch information
jayaddison committed Apr 4, 2023
1 parent afb60c8 commit 758a717
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/js/select2/data/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ define([
return data;
};

SelectAdapter.prototype._normalizeItem = function (item) {
SelectAdapter.prototype._normalizeItem = function (item, recursive) {
if (item !== Object(item)) {
item = {
id: item,
Expand Down Expand Up @@ -278,10 +278,11 @@ define([
item._resultId = this.generateResultId(this.container, item);
}

if (item.children) {
item.children = item.children.map(
SelectAdapter.prototype._normalizeItem
);
// HTML optgroup elements cannot be nested, so limit recursion to depth one
if (item.children && !recursive) {
item.children = item.children.map(function (c) {
return SelectAdapter.prototype._normalizeItem(c, true);
});
}

return $.extend({}, defaults, item);
Expand Down

0 comments on commit 758a717

Please sign in to comment.