Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Fix: XSS Protection
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Lehbert committed May 13, 2011
1 parent 0900eb6 commit 5a05e7e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/jquery.tokeninput.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var DEFAULT_SETTINGS = {
prePopulate: null,
processPrePopulate: false,
makeSortable: false,
escapeHTML: true,
animateDropdown: true,
onResult: null,
onAdd: null,
Expand Down Expand Up @@ -357,7 +358,7 @@ $.TokenList = function (input, url_or_data, settings) {

// Inner function to a token to the list
function insert_token(id, value) {
var this_token = $("<li><p>"+ value +"</p></li>")
var this_token = $("<li><p>"+ escapeHTML(value) +"</p></li>")
.addClass(settings.classes.token)
.insertBefore(input_token);

Expand Down Expand Up @@ -670,7 +671,7 @@ $.TokenList = function (input, url_or_data, settings) {
.hide();

$.each(results, function(index, value) {
var this_li = $("<li>" + highlight_term(value.name, query) + "</li>")
var this_li = $("<li>" + highlight_term(escapeHTML(value.name), query) + "</li>")
.appendTo(dropdown_ul);

if(index % 2) {
Expand Down Expand Up @@ -718,6 +719,13 @@ $.TokenList = function (input, url_or_data, settings) {
item.removeClass(settings.classes.selectedDropdownItem);
selected_dropdown_item = null;
}


function escapeHTML(text) {
if(!settings.escapeHTML) return text;
return $("<p></p>").text(text).html();
}


// Do a search and show the "searching" dropdown if the input is longer
// than settings.minChars
Expand Down

0 comments on commit 5a05e7e

Please sign in to comment.