From 41a519feff05dae5063a50121e662a1d48192b0e Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Tue, 9 Apr 2024 10:26:49 +0200 Subject: [PATCH 1/3] Fixed a bug where the latin-1 encoded message was decoded with utf-8 --- ntfy_lite/ntfy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntfy_lite/ntfy.py b/ntfy_lite/ntfy.py index e47835d..d8da56b 100644 --- a/ntfy_lite/ntfy.py +++ b/ntfy_lite/ntfy.py @@ -53,7 +53,7 @@ def __init__( self._data = open(filepath, "rb") elif message is not None: self._data = message.encode(encoding="UTF-8", errors="replace").decode() - self._data = message.encode(encoding="latin-1", errors="replace").decode() + self._data = message.encode(encoding="latin-1", errors="replace").decode(encoding="latin-1") def __enter__(self) -> typing.Union[typing.IO, str]: return self._data From 4690b7c2a9a27547fb532a63e720817cf1eb6ae0 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Tue, 9 Apr 2024 10:28:10 +0200 Subject: [PATCH 2/3] Removed redundant utf-8 encoding/decoding --- ntfy_lite/ntfy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ntfy_lite/ntfy.py b/ntfy_lite/ntfy.py index d8da56b..098b4a7 100644 --- a/ntfy_lite/ntfy.py +++ b/ntfy_lite/ntfy.py @@ -52,7 +52,6 @@ def __init__( if filepath is not None: self._data = open(filepath, "rb") elif message is not None: - self._data = message.encode(encoding="UTF-8", errors="replace").decode() self._data = message.encode(encoding="latin-1", errors="replace").decode(encoding="latin-1") def __enter__(self) -> typing.Union[typing.IO, str]: From 338695780ff02c27f3e43c21fe8e1958c4b63a37 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Tue, 9 Apr 2024 11:41:44 +0200 Subject: [PATCH 3/3] Added tests for non-ASCII messages --- tests/test_ntfy_lite.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_ntfy_lite.py b/tests/test_ntfy_lite.py index d7ccbce..9bc4d83 100644 --- a/tests/test_ntfy_lite.py +++ b/tests/test_ntfy_lite.py @@ -135,6 +135,20 @@ def test_action_http_push(clear): ntfy.push(topic, title, message=message, actions=action, dry_run=True) +def test_extended_ascii_push(): + topic = "ntfy_lite_test" + title = "ntfy lite test extended ascii push" + message = "ntfy_extended_ascii_push message: (°_°)" + ntfy.push(topic, title, message=message, dry_run=True) + + +def test_unicode_push(): + topic = "ntfy_lite_test" + title = "ntfy lite test unicode push" + message = "ntfy unicode push message: 🐋💐🪂" + ntfy.push(topic, title, message=message, dry_run=True) + + @pytest.mark.parametrize("clear", [True, False]) def test_actions_view_http_push(clear): topic = "ntfy_lite_test"