From 7cc0f8fab05df45e817f724e16648a59667d23e1 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Tue, 15 Nov 2016 17:10:33 +0100 Subject: [PATCH] Add extended encoding message validation - validates variables of the "message" type --- src/messagetypes/message.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/messagetypes/message.py b/src/messagetypes/message.py index aea621cc..0ba97cd9 100644 --- a/src/messagetypes/message.py +++ b/src/messagetypes/message.py @@ -1,13 +1,21 @@ from debug import logger from messagetypes import MsgBase + class Message(MsgBase): def __init__(self): return def decode(self, data): - self.subject = data["subject"] - self.body = data["body"] + # UTF-8 and variable type validator + if type(data["subject"]) is str: + self.subject = unicode(data["subject"], 'utf-8', 'replace') + else: + self.subject = unicode(str(data["subject"]), 'utf-8', 'replace') + if type(data["body"]) is str: + self.body = unicode(data["body"], 'utf-8', 'replace') + else: + self.body = unicode(str(data["body"]), 'utf-8', 'replace') def encode(self, data): super(Message, self).encode()