<commit_before>var messageList,
    userList;

$(document).ready(function(){
	IO = new IO();

	messageList = new MessageList();
	UI = new UI();
	UI.systemMessage("Connecting");
	
	IO.addMessageHandler(messageList);
	IO.connect();
	
	$('#message').keydown(function(e){
		if(e.keyCode == 13){
			var el = $(this),
			    message = $.trim(el.val());
					
			if(message.length > 0){
				IO.socket.send({chan: channel, action:'post', msg:message});
				el.val('');
			}
			
			e.preventDefault();
		}
	});
	
	$('#stats').click(function(e){
		IO.socket.send({chan: channel, action:'stats'});
	});

});


function IO(){
	var socket = this.socket = new io.Socket(window.location.hostname);
	var messageHandlers = [];

	socket.on('connect', function(){
		UI.systemMessage("Connected!");
	});
	
	socket.on('disconnect', function(){
		UI.systemMessage("Disconnected!");
	});
	
	socket.on('message', function(data){
		for(var i=0, len=messageHandlers.length; i<len; i++){
			var handler = messageHandlers[i];
			if(handler.newMessage(data)) break;
		}
	});

	this.connect = function(){
		socket.connect();
		socket.send({channel: channel, action: 'join', session_id: session_id});
	}
	
	this.addMessageHandler = function(handler){
		messageHandlers.push(handler);
	}
}


function UI(){
	IO.socket.on('connect', function(){
		$('#message').attr('disabled', false).focus();
	});
	
	this.appendMessage = function(data){
		var line = $('<div>'),
				nick = $('<div>'),
				msg  = $('<div>');
				
		nick.append(data.from.name);
		nick.addClass('name');
		
		msg.append(data.msg);
		msg.addClass('msg');
		
		line.append(nick, msg);
		line.addClass('line')
		
		$('#messages').append(line);		
	}
	
	this.systemMessage = function(msg){
		this.appendMessage({from:{name: "System"}, msg:msg});		
	}
}

function MessageList(){
	this.list = [];
}

MessageList.prototype.newMessage = function(msg){
	if(msg.action == 'message'){
		UI.appendMessage(msg);
		return true;
	}
}

<commit_msg>HTML Escape messages client-side before they are displayed<commit_after>var messageList,
    userList;

$(document).ready(function(){
	IO = new IO();

	messageList = new MessageList();
	UI = new UI();
	UI.systemMessage("Connecting");
	
	IO.addMessageHandler(messageList);
	IO.connect();
	
	$('#message').keydown(function(e){
		if(e.keyCode == 13){
			var el = $(this),
			    message = $.trim(el.val());
					
			if(message.length > 0){
				IO.socket.send({chan: channel, action:'post', msg:message});
				el.val('');
			}
			
			e.preventDefault();
		}
	});
	
	$('#stats').click(function(e){
		IO.socket.send({chan: channel, action:'stats'});
	});

});


function IO(){
	var socket = this.socket = new io.Socket(window.location.hostname);
	var messageHandlers = [];

	socket.on('connect', function(){
		UI.systemMessage("Connected!");
	});
	
	socket.on('disconnect', function(){
		UI.systemMessage("Disconnected!");
	});
	
	socket.on('message', function(data){
		for(var i=0, len=messageHandlers.length; i<len; i++){
			var handler = messageHandlers[i];
			if(handler.newMessage(data)) break;
		}
	});

	this.connect = function(){
		socket.connect();
		socket.send({channel: channel, action: 'join', session_id: session_id});
	}
	
	this.addMessageHandler = function(handler){
		messageHandlers.push(handler);
	}
}


function UI(){
	IO.socket.on('connect', function(){
		$('#message').attr('disabled', false).focus();
	});
	
	this.appendMessage = function(data){
		var line = $('<div>'),
				nick = $('<div>'),
				msg  = $('<div>');
		
		nick.text(data.from.name);
		nick.addClass('name');
		
		msg.text(data.msg);
		msg.addClass('msg');
		
		line.append(nick, msg);
		line.addClass('line')
		
		$('#messages').append(line);		
	}
	
	this.systemMessage = function(msg){
		this.appendMessage({from:{name: "System"}, msg:msg});		
	}
}

function MessageList(){
	this.list = [];
}

MessageList.prototype.newMessage = function(msg){
	if(msg.action == 'message'){
		UI.appendMessage(msg);
		return true;
	}
}


{'fraction_non_alphanumeric': 0.20735701688082642, 'fraction_numerical': 0.002015621063240111, 'mean_word_length': 4.096277278562259, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5853398', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1336, 'n_words': 233}