From 8b2a788b00f495b4d05d6e2e8b7ce9f3bb63b932 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Sat, 30 Jun 2018 13:42:40 +0000 Subject: [PATCH] Filter non-ASCII input when not in binary mode If the client does not have binary send enabled per prior Telnet option negotiation, filter for non-ASCII characters. This fixes a bug where previously only binary mode senders were checked for non-ASCII input and 7-bit senders were checked for non-UTF-8 input rather than the other way around. --- mudpy/misc.py | 4 ++-- mudpy/tests/selftest.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mudpy/misc.py b/mudpy/misc.py index 439e00a..009de29 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -883,8 +883,8 @@ class User: line = line.strip() # log non-printable characters remaining - if mudpy.telnet.is_enabled(self, mudpy.telnet.TELOPT_BINARY, - mudpy.telnet.HIM): + if not mudpy.telnet.is_enabled( + self, mudpy.telnet.TELOPT_BINARY, mudpy.telnet.HIM): asciiline = bytes([x for x in line if 32 <= x <= 126]) if line != asciiline: logline = "Non-ASCII characters from " diff --git a/mudpy/tests/selftest.py b/mudpy/tests/selftest.py index bf32434..e120e70 100644 --- a/mudpy/tests/selftest.py +++ b/mudpy/tests/selftest.py @@ -151,9 +151,9 @@ test_admin_setup = ( test_telnet_iac = ( # Send a double (escaped) IAC byte within other text, which should get # unescaped and deduplicated to a single \xff in the buffer and then - # the line of input discarded as a non-UTF-8 sequence + # the line of input discarded as a non-ASCII sequence (2, "> ", b"say argle\xff\xffbargle\r\n"), - (2, r"Non-UTF-8 sequence from admin: b'say argle\\xffbargle'.*> ", ""), + (2, r"Non-ASCII characters from admin: b'say argle\\xffbargle'.*> ", ""), ) test_telnet_unknown = ( -- 2.11.0