Merged in html-escape (pull request #50)

Escape HTML provided in form - issue #148
This commit is contained in:
Tom Price
2015-07-29 18:31:11 +01:00

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);