Skip to content

Commit 67a479a

Browse files
committed
Matrix room/alias accepted characters re-aligned - bugfix
1 parent 74d5ad2 commit 67a479a

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

apprise/plugins/matrix.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,19 @@ class MatrixDiscoveryException(AppriseException):
6969

7070
# Matrix Room Syntax
7171
IS_ROOM_ALIAS = re.compile(
72-
r"^\s*(#|%23)?(?P<room>[a-z0-9-]+)((:|%3A)"
73-
r"(?P<home_server>[a-z0-9.-]+))?\s*$",
72+
r"^\s*(#|%23)?(?P<room>[A-Za-z0-9._=-]+)((:|%3A)"
73+
r"(?P<home_server>[A-Za-z0-9.-]+))?\s*$",
7474
re.I,
7575
)
7676

7777
# Room ID MUST start with an exclamation to avoid ambiguity
7878
IS_ROOM_ID = re.compile(
79-
r"^\s*(!|&#33;|%21)(?P<room>[a-z0-9-]+)((:|%3A)"
80-
r"(?P<home_server>[a-z0-9.-]+))?\s*$",
79+
r"^\s*(!|&#33;|%21)(?P<room>[A-Za-z0-9._=-]+)((:|%3A)"
80+
r"(?P<home_server>[A-Za-z0-9.-]+))?\s*$",
8181
re.I,
8282
)
8383

84+
8485
# Matrix is_image check
8586
IS_IMAGE = re.compile(r"^image/.*", re.I)
8687

@@ -254,7 +255,7 @@ class NotifyMatrix(NotifyBase):
254255
"target_room_alias": {
255256
"name": _("Target Room Alias"),
256257
"type": "string",
257-
"prefix": "!",
258+
"prefix": "#",
258259
"map_to": "targets",
259260
},
260261
"targets": {

tests/test_plugin_matrix.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,22 @@ def test_plugin_matrix_url_parsing():
912912
assert "#room2" in result["targets"]
913913
assert "#room3" in result["targets"]
914914

915+
# Mixed-case alias with underscore should parse
916+
result = NotifyMatrix.parse_url(
917+
"matrix://user:token@localhost?to=#Dev_Room:localhost"
918+
)
919+
assert isinstance(result, dict) is True
920+
assert len(result["targets"]) == 1
921+
assert "#Dev_Room:localhost" in result["targets"]
922+
923+
# Mixed-case room id with underscore should be accepted by _room_join
924+
from apprise.plugins.matrix import IS_ROOM_ID # local alias
925+
nm = NotifyMatrix(host="localhost")
926+
nm.access_token = "abc" # simulate logged-in
927+
nm.home_server = "localhost"
928+
# this should NOT be rejected by the regex
929+
assert IS_ROOM_ID.match("!Jm_LvU1nas_8KJPBmN9n:nginx.eu")
930+
915931

916932
@mock.patch("requests.put")
917933
@mock.patch("requests.get")

0 commit comments

Comments
 (0)