Skip to content

Commit e86eac5

Browse files
committed
fix: prevent raw HTML appearing in default element behavior
1 parent 3b7a766 commit e86eac5

File tree

3 files changed

+191
-187
lines changed

3 files changed

+191
-187
lines changed

module/typeahead.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ export class Typeahead {
148148
switch (event.key) {
149149

150150
case 'Tab':
151-
if (this._options.mustMatch) {
151+
const q = this.constructor.behaviours
152+
.query[this._behaviours.query](this)
153+
if (this._options.mustMatch && q) {
152154
this.select()
153155
}
154156
break
@@ -726,7 +728,11 @@ Typeahead.behaviours = {
726728

727729
// Add the suggestion to the element and mark the portion of the
728730
// suggestion that matches the query.
729-
elm.innerHTML = suggestion.label.replace(
731+
732+
const escapeDiv = document.createElement('div')
733+
escapeDiv.textContent = suggestion.label
734+
735+
elm.innerHTML = escapeDiv.innerHTML.replace(
730736
new RegExp($.escapeRegExp(q), 'gi'),
731737
'<mark>$&</mark>'
732738
)

0 commit comments

Comments
 (0)