Skip to content

Commit

Permalink
Merge pull request rstudio#576 from yihui/bugfix/DT-searchbox
Browse files Browse the repository at this point in the history
escape the placeholders of search boxes in DataTables, and strip the HTML tags off
  • Loading branch information
wch committed Aug 26, 2014
2 parents 283f69c + e8ffb68 commit e7e83eb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion inst/www/shared/shiny.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
return val.replace(/([!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g, '\\$1');
};

function escapeHTML(str) {
return str.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;")
.replace(/\//g,"&#x2F;");
}

function randomId() {
return Math.floor(0x100000000 + (Math.random() * 0xF00000000)).toString(16);
}
Expand Down Expand Up @@ -1558,7 +1567,10 @@
var footer = '';
if (data.options === null || data.options.searching !== false) {
footer = $.map(colnames, function(x) {
return '<th><input type="text" placeholder="' + x + '" /></th>';
// placeholder needs to be escaped (and HTML tags are stripped off)
return '<th><input type="text" placeholder="' +
escapeHTML(x.replace(/(<([^>]+)>)/ig, '')) +
'" /></th>';
}).join('');
footer = '<tfoot>' + footer + '</tfoot>';
}
Expand Down

0 comments on commit e7e83eb

Please sign in to comment.