Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash for non-ASCII characters #5

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ntfy_lite/ntfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ 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()
self._data = message.encode(encoding="latin-1", errors="replace").decode(encoding="latin-1")

def __enter__(self) -> typing.Union[typing.IO, str]:
return self._data
Expand Down
14 changes: 14 additions & 0 deletions tests/test_ntfy_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading