mirror of
https://github.com/caronc/apprise.git
synced 2025-12-15 10:04:06 +08:00
matrix:// room/alias character support fixed (#1442)
This commit is contained in:
@@ -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*(!|!|%21)(?P<room>[a-z0-9-]+)((:|%3A)"
|
||||
r"(?P<home_server>[a-z0-9.-]+))?\s*$",
|
||||
r"^\s*(!|!|%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": {
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user