diff --git a/apprise/plugins/matrix.py b/apprise/plugins/matrix.py index 62f00706..b6d27b60 100644 --- a/apprise/plugins/matrix.py +++ b/apprise/plugins/matrix.py @@ -69,18 +69,19 @@ MATRIX_HTTP_ERROR_MAP = { # Matrix Room Syntax IS_ROOM_ALIAS = re.compile( - r"^\s*(#|%23)?(?P[a-z0-9-]+)((:|%3A)" - r"(?P[a-z0-9.-]+))?\s*$", + r"^\s*(#|%23)?(?P[A-Za-z0-9._=-]+)((:|%3A)" + r"(?P[A-Za-z0-9.-]+))?\s*$", re.I, ) # Room ID MUST start with an exclamation to avoid ambiguity IS_ROOM_ID = re.compile( - r"^\s*(!|!|%21)(?P[a-z0-9-]+)((:|%3A)" - r"(?P[a-z0-9.-]+))?\s*$", + r"^\s*(!|!|%21)(?P[A-Za-z0-9._=-]+)((:|%3A)" + r"(?P[A-Za-z0-9.-]+))?\s*$", re.I, ) + # Matrix is_image check IS_IMAGE = re.compile(r"^image/.*", re.I) @@ -254,7 +255,7 @@ class NotifyMatrix(NotifyBase): "target_room_alias": { "name": _("Target Room Alias"), "type": "string", - "prefix": "!", + "prefix": "#", "map_to": "targets", }, "targets": { diff --git a/tests/test_plugin_matrix.py b/tests/test_plugin_matrix.py index d8c4f763..e8630a94 100644 --- a/tests/test_plugin_matrix.py +++ b/tests/test_plugin_matrix.py @@ -912,6 +912,22 @@ def test_plugin_matrix_url_parsing(): assert "#room2" in result["targets"] assert "#room3" in result["targets"] + # Mixed-case alias with underscore should parse + result = NotifyMatrix.parse_url( + "matrix://user:token@localhost?to=#Dev_Room:localhost" + ) + assert isinstance(result, dict) is True + assert len(result["targets"]) == 1 + assert "#Dev_Room:localhost" in result["targets"] + + # Mixed-case room id with underscore should be accepted by _room_join + from apprise.plugins.matrix import IS_ROOM_ID # local alias + nm = NotifyMatrix(host="localhost") + nm.access_token = "abc" # simulate logged-in + nm.home_server = "localhost" + # this should NOT be rejected by the regex + assert IS_ROOM_ID.match("!Jm_LvU1nas_8KJPBmN9n:nginx.eu") + @mock.patch("requests.put") @mock.patch("requests.get")