From e30adb4deea3a3713fb0b0f1244c4debad5ba949 Mon Sep 17 00:00:00 2001 From: Fabio Lucattini Date: Wed, 17 Jul 2024 21:45:56 +0200 Subject: [PATCH] fix: conversion html_to_text hr tags rstrip non string object (#1162) Co-authored-by: Fabio Lucattini --- apprise/conversion.py | 4 ++- test/test_conversion.py | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/apprise/conversion.py b/apprise/conversion.py index 5b6d1a94..366fe8e3 100644 --- a/apprise/conversion.py +++ b/apprise/conversion.py @@ -180,8 +180,10 @@ class HTMLConverter(HTMLParser, object): self._result.append('\n') elif tag == 'hr': - if self._result: + if self._result and isinstance(self._result[-1], str): self._result[-1] = self._result[-1].rstrip(' ') + else: + pass self._result.append('\n---\n') diff --git a/test/test_conversion.py b/test/test_conversion.py index e2a64401..19fddce7 100644 --- a/test/test_conversion.py +++ b/test/test_conversion.py @@ -127,6 +127,70 @@ def test_conversion_html_to_text(): # If you give nothing, you get nothing in return assert to_html("") == "" + # Special case on HR tag + assert to_html(""" + + + +

FROM: apprise-test@mydomain.yyy +

+ Hi!
+ How are you?
+red font +link you wanted.
+ + + """) == "FROM: apprise-test@mydomain.yyy\nHi!\n How are you?\n \ +red font link you wanted." + + assert to_html(""" + + + +

FROM: apprise-test@mydomain.yyy +


+ Hi!
+ How are you?
+red font +link you wanted.
+ + + """) == "FROM: apprise-test@mydomain.yyy\n---\nHi!\n \ +How are you?\n red font link you wanted." + + # Special case on HR if text is sorrunded by HR tags + # its created a dict element + assert to_html(""" + + + +


FROM: apprise-test@mydomain.yyy +

+ Hi!
+ How are you?
+red font +link you wanted.
+ + + """) == "---\nFROM: apprise-test@mydomain.yyy\n---\nHi!\n \ +How are you?\n red font link you wanted." + + assert to_html(""" + + + +

+


TEST
+

+ Hi!
+ How are you?
+red font +link you wanted.
+ + + """) == "---\nTEST\n---\nHi!\n How are you?\n red font link you \ +wanted." + with pytest.raises(TypeError): # Invalid input assert to_html(None)