From 8a1fdb834b6be88e507a0d90f5cc5216590e35ff Mon Sep 17 00:00:00 2001 From: Griatch Date: Thu, 8 Feb 2018 20:35:00 +0100 Subject: [PATCH 1/2] Be more lenient with iterables sent to msg(text=..) This will enforce that the text argument must either be a string or a tuple. --- evennia/accounts/accounts.py | 9 ++++++++- evennia/objects/objects.py | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index c127e71494..b90b5ac8ab 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -21,7 +21,7 @@ from evennia.objects.models import ObjectDB from evennia.comms.models import ChannelDB from evennia.commands import cmdhandler from evennia.utils import logger -from evennia.utils.utils import (lazy_property, +from evennia.utils.utils import (lazy_property, to_str, make_iter, to_unicode, is_iter, variable_from_module) from evennia.typeclasses.attributes import NickHandler @@ -421,6 +421,13 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)): kwargs["options"] = options + if text and not (isinstance(text, basestring) or isinstance(text, tuple)): + # sanitize text before sending across the wire + try: + text = to_str(text, force_string=True) + except Exception: + text = repr(text) + # session relay sessions = make_iter(session) if session else self.sessions.all() for session in sessions: diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index 0d5f85b695..5531b7f856 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -22,7 +22,7 @@ from evennia.commands import cmdhandler from evennia.utils import search from evennia.utils import logger from evennia.utils.utils import (variable_from_module, lazy_property, - make_iter, to_unicode, is_iter) + make_iter, to_unicode, is_iter, to_str) from django.utils.translation import ugettext as _ _MULTISESSION_MODE = settings.MULTISESSION_MODE @@ -528,11 +528,19 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)): kwargs["options"] = options + if text and not (isinstance(text, basestring) or isinstance(text, tuple)): + # sanitize text before sending across the wire + try: + text = to_str(text, force_string=True) + except Exception: + text = repr(text) + # relay to session(s) sessions = make_iter(session) if session else self.sessions.all() for session in sessions: session.data_out(text=text, **kwargs) + def for_contents(self, func, exclude=None, **kwargs): """ Runs a function on every object contained within this one. From 9eacd7a81bb65ce355e1a3cc26baffc2472438ac Mon Sep 17 00:00:00 2001 From: Griatch Date: Thu, 8 Feb 2018 21:08:19 +0100 Subject: [PATCH 2/2] Start better handle a missing uid with auto-login (still issues) --- evennia/web/webclient/views.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/evennia/web/webclient/views.py b/evennia/web/webclient/views.py index 94ecffb0e2..439dd44ad2 100644 --- a/evennia/web/webclient/views.py +++ b/evennia/web/webclient/views.py @@ -34,7 +34,13 @@ def _shared_login(request): if webclient_uid: # The webclient has previously registered a login to this browser_session if not account.is_authenticated() and not website_uid: - account = AccountDB.objects.get(id=webclient_uid) + try: + account = AccountDB.objects.get(id=webclient_uid) + except AccountDB.DoesNotExist: + # this can happen e.g. for guest accounts or deletions + csession["website_authenticated_uid"] = False + csession["webclient_authenticated_uid"] = False + return try: # calls our custom authenticate in web/utils/backends.py account = authenticate(autologin=account)