Skip to content
This repository was archived by the owner on Sep 10, 2023. It is now read-only.

Commit c0f9097

Browse files
author
Wilson Lee
committed
Escape HTML in more places
1 parent 5d9de3f commit c0f9097

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/jquery.tokeninput.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var DEFAULT_SETTINGS = {
3434
zindex: 999,
3535
resultsLimit: null,
3636

37-
enableHTML: true,
37+
enableHTML: false,
3838

3939
resultsFormatter: function(item) {
4040
var string = item[this.propertyToSearch];
@@ -529,8 +529,7 @@ $.TokenList = function (input, url_or_data, settings) {
529529
if(input_val === (input_val = input_box.val())) {return;}
530530

531531
// Enter new content into resizer and resize input accordingly
532-
var escaped = input_val.replace(/&/g, '&amp;').replace(/\s/g,' ').replace(/</g, '&lt;').replace(/>/g, '&gt;');
533-
input_resizer.html(escaped);
532+
input_resizer.html(_escapeHTML(input_val));
534533
input_box.width(input_resizer.width() + 30);
535534
}
536535

@@ -747,14 +746,14 @@ $.TokenList = function (input, url_or_data, settings) {
747746

748747
function show_dropdown_searching () {
749748
if(settings.searchingText) {
750-
dropdown.html("<p>"+settings.searchingText+"</p>");
749+
dropdown.html("<p>" + escapeHTML(settings.searchingText) + "</p>");
751750
show_dropdown();
752751
}
753752
}
754753

755754
function show_dropdown_hint () {
756755
if(settings.hintText) {
757-
dropdown.html("<p>"+settings.hintText+"</p>");
756+
dropdown.html("<p>" + escapeHTML(settings.hintText) + "</p>");
758757
show_dropdown();
759758
}
760759
}
@@ -766,7 +765,14 @@ $.TokenList = function (input, url_or_data, settings) {
766765

767766
// Highlight the query part of the search term
768767
function highlight_term(value, term) {
769-
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + regexp_escape(term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
768+
return value.replace(
769+
new RegExp(
770+
"(?![^&;]+;)(?!<[^<>]*)(" + regexp_escape(term) + ")(?![^<>]*>)(?![^&;]+;)",
771+
"gi"
772+
), function(match, p1) {
773+
return "<b>" + escapeHTML(p1) + "</b>";
774+
}
775+
);
770776
}
771777

772778
function find_value_and_highlight_term(template, value, term) {
@@ -822,7 +828,7 @@ $.TokenList = function (input, url_or_data, settings) {
822828
}
823829
} else {
824830
if(settings.noResultsText) {
825-
dropdown.html("<p>"+settings.noResultsText+"</p>");
831+
dropdown.html("<p>" + escapeHTML(settings.noResultsText) + "</p>");
826832
show_dropdown();
827833
}
828834
}

0 commit comments

Comments
 (0)