Escape HTML provided in form - issue #148

This commit is contained in:
David Taylor
2015-07-20 22:02:08 +01:00
parent 5b3bc591b8
commit c67eab3479

View File

@@ -11,6 +11,10 @@ function nl2br (str, is_xhtml) {
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}
function escapeHtml (str) {
return $('<div/>').text(str).html();
}
function updatePrices() {
// individual rows
var sum = 0;
@@ -101,8 +105,8 @@ $('body').on('submit', '#item-form', function (e) {
}
// update the table
$row = $('#item-' + pk);
$row.find('.name').html(fields.name);
$row.find('.description').html(nl2br(fields.description));
$row.find('.name').html(escapeHtml(fields.name));
$row.find('.description').html(nl2br(escapeHtml(fields.description)));
$row.find('.cost').html(parseFloat(fields.cost).toFixed(2));
$row.find('.quantity').html(fields.quantity);