mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-10 03:37:28 -03:00
Checks if username is ASCII string else throw an error
This commit is contained in:
parent
97fe219e21
commit
98f6f3b7d7
2 changed files with 12 additions and 1 deletions
|
@ -82,7 +82,7 @@ var emitMessage = function (socket) {
|
||||||
|
|
||||||
var updateUsername = function (socket) {
|
var updateUsername = function (socket) {
|
||||||
var username = $('#username').val();
|
var username = $('#username').val();
|
||||||
if (!checkUsernameExists(username) && !checkUsernameTooLong(username)) {
|
if (!checkUsernameExists(username) && !checkUsernameTooLong(username) && !checkUsernameAscii(username)) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: `http://${document.domain}:${location.port}/update-session-username`,
|
url: `http://${document.domain}:${location.port}/update-session-username`,
|
||||||
|
@ -117,6 +117,16 @@ var createUserListHTML = function (connected_users, current_user) {
|
||||||
return userListHTML;
|
return userListHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var checkUsernameAscii = function (username) {
|
||||||
|
// ASCII characters have code points in the range U+0000-U+007F.
|
||||||
|
$('#username-error').text('');
|
||||||
|
if (!/^[\u0000-\u007f]*$/.test(username)) {
|
||||||
|
$('#username-error').text('Non-ASCII usernames are not supported.');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var checkUsernameExists = function (username) {
|
var checkUsernameExists = function (username) {
|
||||||
$('#username-error').text('');
|
$('#username-error').text('');
|
||||||
var userMatches = $('#user-list li').filter(function () {
|
var userMatches = $('#user-list li').filter(function () {
|
||||||
|
|
|
@ -51,6 +51,7 @@ class ChatModeWeb:
|
||||||
username = username.strip()
|
username = username.strip()
|
||||||
return (
|
return (
|
||||||
username
|
username
|
||||||
|
and username.isascii()
|
||||||
and username not in self.connected_users
|
and username not in self.connected_users
|
||||||
and len(username) < 128
|
and len(username) < 128
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue