matrix:// room/alias character support fixed (#1442)

This commit is contained in:
Chris Caron
2025-11-05 23:17:50 -05:00
committed by GitHub
parent 91b6f91094
commit eea03d1b68
2 changed files with 22 additions and 5 deletions

View File

@@ -69,18 +69,19 @@ MATRIX_HTTP_ERROR_MAP = {
# Matrix Room Syntax
IS_ROOM_ALIAS = re.compile(
r"^\s*(#|%23)?(?P<room>[a-z0-9-]+)((:|%3A)"
r"(?P<home_server>[a-z0-9.-]+))?\s*$",
r"^\s*(#|%23)?(?P<room>[A-Za-z0-9._=-]+)((:|%3A)"
r"(?P<home_server>[A-Za-z0-9.-]+))?\s*$",
re.I,
)
# Room ID MUST start with an exclamation to avoid ambiguity
IS_ROOM_ID = re.compile(
r"^\s*(!|&#33;|%21)(?P<room>[a-z0-9-]+)((:|%3A)"
r"(?P<home_server>[a-z0-9.-]+))?\s*$",
r"^\s*(!|&#33;|%21)(?P<room>[A-Za-z0-9._=-]+)((:|%3A)"
r"(?P<home_server>[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": {

View File

@@ -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")