mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Sanitize message before appending them to the HTML
This commit is contained in:
parent
819e406d46
commit
7eaefd5299
@ -6,11 +6,11 @@ $(function(){
|
|||||||
socket.emit('joined', {});
|
socket.emit('joined', {});
|
||||||
});
|
});
|
||||||
socket.on('status', function(data) {
|
socket.on('status', function(data) {
|
||||||
$('#chat').append('<p><small><i>' + data.msg + '</i></small></p>');
|
$('#chat').append('<p><small><i>' + sanitizeHTML(data.msg) + '</i></small></p>');
|
||||||
$('#chat').scrollTop($('#chat')[0].scrollHeight);
|
$('#chat').scrollTop($('#chat')[0].scrollHeight);
|
||||||
});
|
});
|
||||||
socket.on('message', function(data) {
|
socket.on('message', function(data) {
|
||||||
$('#chat').append('<p>' + data.msg + '</p>');
|
$('#chat').append('<p>' + sanitizeHTML(data.msg) + '</p>');
|
||||||
$('#chat').scrollTop($('#chat')[0].scrollHeight);
|
$('#chat').scrollTop($('#chat')[0].scrollHeight);
|
||||||
});
|
});
|
||||||
$('#new-message').on('keypress', function(e) {
|
$('#new-message').on('keypress', function(e) {
|
||||||
@ -23,8 +23,14 @@ $(function(){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function emitMessage(socket) {
|
var emitMessage = function(socket) {
|
||||||
text = $('#new-message').val();
|
text = $('#new-message').val();
|
||||||
$('#new-message').val('');
|
$('#new-message').val('');
|
||||||
socket.emit('text', {msg: text});
|
socket.emit('text', {msg: text});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sanitizeHTML = function(str) {
|
||||||
|
var temp = document.createElement('span');
|
||||||
|
temp.textContent = str;
|
||||||
|
return temp.innerHTML;
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user