Skip to content

Commit

Permalink
#43 リファクタリング.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneyan committed Sep 15, 2024
1 parent fd4c913 commit 69f9199
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion dsbd/templates/custom_admin/ticket/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,19 @@ <h6 class="m-b-0">{{ user.username }}</h6>
}
}

function escapeHTML(str) {
return str.replace(/[&<>"']/g, function (match) {
const escape = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'
};
return escape[match];
});
}

function connect() {
const wsScheme = (window.location.protocol === 'https:' ? 'wss' : 'ws');
const hostname = window.location.host;
Expand All @@ -360,7 +373,7 @@ <h6 class="m-b-0">{{ user.username }}</h6>
console.log(data);
let element = document.getElementById('chat_websocket');

let message = data.message.replace(/\n/, '<br>');
let message = escapeHTML(data.message).replace(/\n/g, '<br>');
let html = '<li class="clearfix">';
if (data.username === '{{ request.user.username }}' && data.is_admin) {
html += '<div class="message-data text-end">';
Expand Down

0 comments on commit 69f9199

Please sign in to comment.