Skip to content

Commit 5d3d13e

Browse files
committed
Fixed #54 - Support correct HTML encoding
1 parent a43da71 commit 5d3d13e

5 files changed

+29
-7
lines changed

demos/default.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<form>
1515
<select id="test">
1616
<option value="Select a Month bithcesdjaldkjlakjs">Select a Month</option>
17-
<option value="January">January</option>
17+
<option value="1">Some Text &lt;strike&gt;bad&lt;/strike&gt; good</option>
1818
<option value="February">February</option>
1919
<option value="March">March</option>
2020
<option value="April">April</option>

src/javascripts/jquery.selectBoxIt.core.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@
337337

338338
}
339339

340-
// Uses Array.join instead of string concatenation for speed (applies HTML attribute encoding for quotes)
341-
currentItem += optgroupElement + '<li id="' + index + '" data-val="' + this.value.replace(/\"/g,'&quot;') + '" data-disabled="' + dataDisabled + '" class="' + optgroupClass + " selectboxit-option" + ($(this).attr("class") || "") + '" style="' + ($(this).attr("style") || "") + '"><a class="selectboxit-option-anchor"><i class="selectboxit-option-icon ' + iconClass + '"></i>' + $(this).text() + '</a></li>';
340+
// Uses Array.join instead of string concatenation for speed (applies HTML attribute encoding)
341+
currentItem += optgroupElement + '<li id="' + index + '" data-val="' + self.htmlEscape(this.value) + '" data-disabled="' + dataDisabled + '" class="' + optgroupClass + " selectboxit-option" + ($(this).attr("class") || "") + '" style="' + ($(this).attr("style") || "") + '"><a class="selectboxit-option-anchor"><i class="selectboxit-option-icon ' + iconClass + '"></i>' + self.htmlEscape($(this).text()) + '</a></li>';
342342

343343
// Stores all of the original select box options text inside of an array
344344
// (Used later in the `searchAlgorithm` method)
@@ -1442,6 +1442,17 @@
14421442

14431443
});
14441444

1445+
},
1446+
1447+
htmlEscape: function(str) {
1448+
1449+
return String(str)
1450+
.replace(/&/g, '&amp;')
1451+
.replace(/"/g, '&quot;')
1452+
.replace(/'/g, '&#39;')
1453+
.replace(/</g, '&lt;')
1454+
.replace(/>/g, '&gt;');
1455+
14451456
}
14461457

14471458
});

0 commit comments

Comments
 (0)