Skip to content

Commit e8ffb68

Browse files
committed
escape the placeholders of search boxes in DataTables, and strip the HTML tags off
1 parent 283f69c commit e8ffb68

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

inst/www/shared/shiny.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
return val.replace(/([!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g, '\\$1');
2525
};
2626

27+
function escapeHTML(str) {
28+
return str.replace(/&/g, "&amp;")
29+
.replace(/</g, "&lt;")
30+
.replace(/>/g, "&gt;")
31+
.replace(/"/g, "&quot;")
32+
.replace(/'/g, "&#039;")
33+
.replace(/\//g,"&#x2F;");
34+
}
35+
2736
function randomId() {
2837
return Math.floor(0x100000000 + (Math.random() * 0xF00000000)).toString(16);
2938
}
@@ -1558,7 +1567,10 @@
15581567
var footer = '';
15591568
if (data.options === null || data.options.searching !== false) {
15601569
footer = $.map(colnames, function(x) {
1561-
return '<th><input type="text" placeholder="' + x + '" /></th>';
1570+
// placeholder needs to be escaped (and HTML tags are stripped off)
1571+
return '<th><input type="text" placeholder="' +
1572+
escapeHTML(x.replace(/(<([^>]+)>)/ig, '')) +
1573+
'" /></th>';
15621574
}).join('');
15631575
footer = '<tfoot>' + footer + '</tfoot>';
15641576
}

0 commit comments

Comments
 (0)