aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2021-11-19 11:24:57 -0800
committerGitHub <noreply@github.com>2021-11-19 11:24:57 -0800
commit97fe219e21a1fc6dc08a3627711f57f5bae74497 (patch)
treee9fe7b8a576af022f0a5665caee42cfcf3305e28
parent092cbc12ced67bc445f8e2af96b21ce2926c08b7 (diff)
parent2a68b5bce11f9b5aba7887c96eeb439e74269dad (diff)
downloadonionshare-97fe219e21a1fc6dc08a3627711f57f5bae74497.tar.gz
onionshare-97fe219e21a1fc6dc08a3627711f57f5bae74497.zip
Merge pull request #1 from onionshare/otf-5
Removes invisible whitespace characters from username in chat
-rw-r--r--cli/onionshare_cli/resources/static/js/chat.js2
-rw-r--r--cli/onionshare_cli/web/chat_mode.py11
2 files changed, 8 insertions, 5 deletions
diff --git a/cli/onionshare_cli/resources/static/js/chat.js b/cli/onionshare_cli/resources/static/js/chat.js
index 5beb022f..a221106c 100644
--- a/cli/onionshare_cli/resources/static/js/chat.js
+++ b/cli/onionshare_cli/resources/static/js/chat.js
@@ -9,7 +9,7 @@ $(function () {
);
// Store current username received from app context
- var current_username = $('#username').val();
+ var current_username = $('#username').val().trim();
// Triggered on any status change by any user, such as some
// user joined, or changed username, or left, etc.
diff --git a/cli/onionshare_cli/web/chat_mode.py b/cli/onionshare_cli/web/chat_mode.py
index b7ccbeb9..3eda2867 100644
--- a/cli/onionshare_cli/web/chat_mode.py
+++ b/cli/onionshare_cli/web/chat_mode.py
@@ -48,6 +48,7 @@ class ChatModeWeb:
self.define_routes()
def validate_username(self, username):
+ username = username.strip()
return (
username
and username not in self.connected_users
@@ -85,8 +86,9 @@ class ChatModeWeb:
def update_session_username():
history_id = self.cur_history_id
data = request.get_json()
- if self.validate_username(data.get("username", "")):
- session["name"] = data.get("username", session.get("name"))
+ username = data.get("username", session.get("name")).strip()
+ if self.validate_username(username):
+ session["name"] = username
self.web.add_request(
request.path,
{"id": history_id, "status_code": 200},
@@ -147,8 +149,9 @@ class ChatModeWeb:
"""Sent by a client when the user updates their username.
The message is sent to all people in the server."""
current_name = session.get("name")
- if self.validate_username(message.get("username", "")):
- session["name"] = message["username"]
+ new_name = message.get("username", "").strip()
+ if self.validate_username(new_name):
+ session["name"] = new_name
self.connected_users[
self.connected_users.index(current_name)
] = session.get("name")