diff --git a/telegram/message.py b/telegram/message.py index f67a3018d..38a30f962 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -868,6 +868,9 @@ class Message(TelegramObject): @staticmethod def _parse_html(message_text, entities, urled=False): + if message_text is None: + return None + if not sys.maxunicode == 0xffff: message_text = message_text.encode('utf-16-le') @@ -962,6 +965,9 @@ class Message(TelegramObject): @staticmethod def _parse_markdown(message_text, entities, urled=False): + if message_text is None: + return None + if not sys.maxunicode == 0xffff: message_text = message_text.encode('utf-16-le') diff --git a/tests/test_message.py b/tests/test_message.py index 2ce115fd3..b09971ff7 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -173,6 +173,11 @@ class TestMessage(object): text_html = self.test_message.text_html assert text_html == test_html_string + def test_text_html_empty(self, message): + message.text = None + message.caption = "test" + assert message.text_html is None + def test_text_html_urled(self): test_html_string = ('Test for <bold, ita_lic, code, ' 'links and
pre
. ' @@ -186,6 +191,11 @@ class TestMessage(object): text_markdown = self.test_message.text_markdown assert text_markdown == test_md_string + def test_text_markdown_empty(self, message): + message.text = None + message.caption = "test" + assert message.text_markdown is None + def test_text_markdown_urled(self): test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' '```pre```. [http://google.com](http://google.com)') @@ -215,6 +225,11 @@ class TestMessage(object): caption_html = self.test_message.caption_html assert caption_html == test_html_string + def test_caption_html_empty(self, message): + message.text = "test" + message.caption = None + assert message.caption_html is None + def test_caption_html_urled(self): test_html_string = ('Test for <bold, ita_lic, code, ' 'links and
pre
. ' @@ -228,6 +243,11 @@ class TestMessage(object): caption_markdown = self.test_message.caption_markdown assert caption_markdown == test_md_string + def test_caption_markdown_empty(self, message): + message.text = "test" + message.caption = None + assert message.caption_markdown is None + def test_caption_markdown_urled(self): test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' '```pre```. [http://google.com](http://google.com)')