Add function htmlEntities

`htmlentities()` is a function which converts special characters. This allows you to show to display the string without the browser reading it as HTML.
This commit is contained in:
lethanhphuc 2021-11-11 17:32:09 +07:00 committed by GitHub
parent 3f245871ac
commit 2c7065e0c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -331,6 +331,10 @@
return "{% url 'helpdesk:view' 1234 %}".replace(/1234/, row.id.toString()); return "{% url 'helpdesk:view' 1234 %}".replace(/1234/, row.id.toString());
} }
function htmlEntities(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
$(document).ready(function () { $(document).ready(function () {
// Ticket DataTable Initialization // Ticket DataTable Initialization
$('#ticketTable').DataTable({ $('#ticketTable').DataTable({
@ -366,7 +370,7 @@
if (type === 'display') { if (type === 'display') {
data = '<div class="tickettitle"><a href="' + get_url(row) + '" >' + data = '<div class="tickettitle"><a href="' + get_url(row) + '" >' +
row.id + '. ' + row.id + '. ' +
row.title + '</a></div>'; htmlEntities(row.title) + '</a></div>';
} }
return data return data
} }