diff options
author | Micah Lee <micah@micahflee.com> | 2021-11-29 20:31:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-29 20:31:12 -0800 |
commit | 74711e7d7c7b825fc580c612530569195156794a (patch) | |
tree | 53b67b4a9b1bceef1940234a3b9132e31b5d3d92 | |
parent | 97fe219e21a1fc6dc08a3627711f57f5bae74497 (diff) | |
parent | 98f6f3b7d7cb390ea9536bf5fd2e4743be9b9fd4 (diff) | |
download | onionshare-74711e7d7c7b825fc580c612530569195156794a.tar.gz onionshare-74711e7d7c7b825fc580c612530569195156794a.zip |
Merge pull request #2 from onionshare/ascii-username-check
Checks if username is ASCII string else throw an error
-rw-r--r-- | cli/onionshare_cli/resources/static/js/chat.js | 12 | ||||
-rw-r--r-- | cli/onionshare_cli/web/chat_mode.py | 1 |
2 files changed, 12 insertions, 1 deletions
diff --git a/cli/onionshare_cli/resources/static/js/chat.js b/cli/onionshare_cli/resources/static/js/chat.js index a221106c..21f00ca6 100644 --- a/cli/onionshare_cli/resources/static/js/chat.js +++ b/cli/onionshare_cli/resources/static/js/chat.js @@ -82,7 +82,7 @@ var emitMessage = function (socket) { var updateUsername = function (socket) { var username = $('#username').val(); - if (!checkUsernameExists(username) && !checkUsernameTooLong(username)) { + if (!checkUsernameExists(username) && !checkUsernameTooLong(username) && !checkUsernameAscii(username)) { $.ajax({ method: 'POST', url: `http://${document.domain}:${location.port}/update-session-username`, @@ -117,6 +117,16 @@ var createUserListHTML = function (connected_users, current_user) { 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) { $('#username-error').text(''); var userMatches = $('#user-list li').filter(function () { diff --git a/cli/onionshare_cli/web/chat_mode.py b/cli/onionshare_cli/web/chat_mode.py index 3eda2867..f6aead45 100644 --- a/cli/onionshare_cli/web/chat_mode.py +++ b/cli/onionshare_cli/web/chat_mode.py @@ -51,6 +51,7 @@ class ChatModeWeb: username = username.strip() return ( username + and username.isascii() and username not in self.connected_users and len(username) < 128 ) |