mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Merge pull request #1 from onionshare/otf-5
Removes invisible whitespace characters from username in chat
This commit is contained in:
commit
97fe219e21
@ -9,7 +9,7 @@ $(function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Store current username received from app context
|
// 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
|
// Triggered on any status change by any user, such as some
|
||||||
// user joined, or changed username, or left, etc.
|
// user joined, or changed username, or left, etc.
|
||||||
|
@ -48,6 +48,7 @@ class ChatModeWeb:
|
|||||||
self.define_routes()
|
self.define_routes()
|
||||||
|
|
||||||
def validate_username(self, username):
|
def validate_username(self, username):
|
||||||
|
username = username.strip()
|
||||||
return (
|
return (
|
||||||
username
|
username
|
||||||
and username not in self.connected_users
|
and username not in self.connected_users
|
||||||
@ -85,8 +86,9 @@ class ChatModeWeb:
|
|||||||
def update_session_username():
|
def update_session_username():
|
||||||
history_id = self.cur_history_id
|
history_id = self.cur_history_id
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if self.validate_username(data.get("username", "")):
|
username = data.get("username", session.get("name")).strip()
|
||||||
session["name"] = data.get("username", session.get("name"))
|
if self.validate_username(username):
|
||||||
|
session["name"] = username
|
||||||
self.web.add_request(
|
self.web.add_request(
|
||||||
request.path,
|
request.path,
|
||||||
{"id": history_id, "status_code": 200},
|
{"id": history_id, "status_code": 200},
|
||||||
@ -147,8 +149,9 @@ class ChatModeWeb:
|
|||||||
"""Sent by a client when the user updates their username.
|
"""Sent by a client when the user updates their username.
|
||||||
The message is sent to all people in the server."""
|
The message is sent to all people in the server."""
|
||||||
current_name = session.get("name")
|
current_name = session.get("name")
|
||||||
if self.validate_username(message.get("username", "")):
|
new_name = message.get("username", "").strip()
|
||||||
session["name"] = message["username"]
|
if self.validate_username(new_name):
|
||||||
|
session["name"] = new_name
|
||||||
self.connected_users[
|
self.connected_users[
|
||||||
self.connected_users.index(current_name)
|
self.connected_users.index(current_name)
|
||||||
] = session.get("name")
|
] = session.get("name")
|
||||||
|
Loading…
Reference in New Issue
Block a user