mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-27 04:39:24 -05:00
Consistently url decode and decode as utf 8 the URL parts
This commit is contained in:
parent
c39beb5559
commit
7b43a503f3
@ -29,6 +29,7 @@ from twisted.web.util import redirectTo
|
|||||||
|
|
||||||
import collections
|
import collections
|
||||||
import logging
|
import logging
|
||||||
|
import urllib
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -122,9 +123,18 @@ class JsonResource(HttpServer, resource.Resource):
|
|||||||
# We found a match! Trigger callback and then return the
|
# We found a match! Trigger callback and then return the
|
||||||
# returned response. We pass both the request and any
|
# returned response. We pass both the request and any
|
||||||
# matched groups from the regex to the callback.
|
# matched groups from the regex to the callback.
|
||||||
|
|
||||||
|
logger.debug("url things: %r", m.groups())
|
||||||
|
|
||||||
|
args = [
|
||||||
|
urllib.unquote(u).decode("UTF-8") for u in m.groups()
|
||||||
|
]
|
||||||
|
|
||||||
|
logger.debug("url things args: %r", args)
|
||||||
|
|
||||||
code, response = yield path_entry.callback(
|
code, response = yield path_entry.callback(
|
||||||
request,
|
request,
|
||||||
*m.groups()
|
*args
|
||||||
)
|
)
|
||||||
|
|
||||||
self._send_response(request, code, response)
|
self._send_response(request, code, response)
|
||||||
|
@ -36,9 +36,7 @@ class ClientDirectoryServer(RestServlet):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, request, room_alias):
|
def on_GET(self, request, room_alias):
|
||||||
room_alias = self.hs.parse_roomalias(
|
room_alias = self.hs.parse_roomalias(room_alias)
|
||||||
urllib.unquote(room_alias).decode("utf-8")
|
|
||||||
)
|
|
||||||
|
|
||||||
dir_handler = self.handlers.directory_handler
|
dir_handler = self.handlers.directory_handler
|
||||||
res = yield dir_handler.get_association(room_alias)
|
res = yield dir_handler.get_association(room_alias)
|
||||||
@ -56,9 +54,7 @@ class ClientDirectoryServer(RestServlet):
|
|||||||
|
|
||||||
logger.debug("Got content: %s", content)
|
logger.debug("Got content: %s", content)
|
||||||
|
|
||||||
room_alias = self.hs.parse_roomalias(
|
room_alias = self.hs.parse_roomalias(room_alias)
|
||||||
urllib.unquote(room_alias).decode("utf-8")
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.debug("Got room name: %s", room_alias.to_string())
|
logger.debug("Got room name: %s", room_alias.to_string())
|
||||||
|
|
||||||
@ -97,9 +93,7 @@ class ClientDirectoryServer(RestServlet):
|
|||||||
|
|
||||||
dir_handler = self.handlers.directory_handler
|
dir_handler = self.handlers.directory_handler
|
||||||
|
|
||||||
room_alias = self.hs.parse_roomalias(
|
room_alias = self.hs.parse_roomalias(room_alias)
|
||||||
urllib.unquote(room_alias).decode("utf-8")
|
|
||||||
)
|
|
||||||
|
|
||||||
yield dir_handler.delete_association(
|
yield dir_handler.delete_association(
|
||||||
user.to_string(), room_alias
|
user.to_string(), room_alias
|
||||||
|
@ -33,7 +33,6 @@ class PresenceStatusRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, request, user_id):
|
def on_GET(self, request, user_id):
|
||||||
auth_user = yield self.auth.get_user_by_req(request)
|
auth_user = yield self.auth.get_user_by_req(request)
|
||||||
user_id = urllib.unquote(user_id)
|
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
state = yield self.handlers.presence_handler.get_state(
|
state = yield self.handlers.presence_handler.get_state(
|
||||||
@ -44,7 +43,6 @@ class PresenceStatusRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_PUT(self, request, user_id):
|
def on_PUT(self, request, user_id):
|
||||||
auth_user = yield self.auth.get_user_by_req(request)
|
auth_user = yield self.auth.get_user_by_req(request)
|
||||||
user_id = urllib.unquote(user_id)
|
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
state = {}
|
state = {}
|
||||||
@ -80,7 +78,6 @@ class PresenceListRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, request, user_id):
|
def on_GET(self, request, user_id):
|
||||||
auth_user = yield self.auth.get_user_by_req(request)
|
auth_user = yield self.auth.get_user_by_req(request)
|
||||||
user_id = urllib.unquote(user_id)
|
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
if not self.hs.is_mine(user):
|
if not self.hs.is_mine(user):
|
||||||
@ -101,7 +98,6 @@ class PresenceListRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_POST(self, request, user_id):
|
def on_POST(self, request, user_id):
|
||||||
auth_user = yield self.auth.get_user_by_req(request)
|
auth_user = yield self.auth.get_user_by_req(request)
|
||||||
user_id = urllib.unquote(user_id)
|
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
if not self.hs.is_mine(user):
|
if not self.hs.is_mine(user):
|
||||||
|
@ -27,7 +27,6 @@ class ProfileDisplaynameRestServlet(RestServlet):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, request, user_id):
|
def on_GET(self, request, user_id):
|
||||||
user_id = urllib.unquote(user_id)
|
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
displayname = yield self.handlers.profile_handler.get_displayname(
|
displayname = yield self.handlers.profile_handler.get_displayname(
|
||||||
@ -39,7 +38,6 @@ class ProfileDisplaynameRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_PUT(self, request, user_id):
|
def on_PUT(self, request, user_id):
|
||||||
auth_user = yield self.auth.get_user_by_req(request)
|
auth_user = yield self.auth.get_user_by_req(request)
|
||||||
user_id = urllib.unquote(user_id)
|
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -62,7 +60,6 @@ class ProfileAvatarURLRestServlet(RestServlet):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, request, user_id):
|
def on_GET(self, request, user_id):
|
||||||
user_id = urllib.unquote(user_id)
|
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
avatar_url = yield self.handlers.profile_handler.get_avatar_url(
|
avatar_url = yield self.handlers.profile_handler.get_avatar_url(
|
||||||
@ -74,7 +71,6 @@ class ProfileAvatarURLRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_PUT(self, request, user_id):
|
def on_PUT(self, request, user_id):
|
||||||
auth_user = yield self.auth.get_user_by_req(request)
|
auth_user = yield self.auth.get_user_by_req(request)
|
||||||
user_id = urllib.unquote(user_id)
|
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -97,7 +93,6 @@ class ProfileRestServlet(RestServlet):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, request, user_id):
|
def on_GET(self, request, user_id):
|
||||||
user_id = urllib.unquote(user_id)
|
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
displayname = yield self.handlers.profile_handler.get_displayname(
|
displayname = yield self.handlers.profile_handler.get_displayname(
|
||||||
|
@ -129,9 +129,9 @@ class RoomStateEventRestServlet(RestServlet):
|
|||||||
msg_handler = self.handlers.message_handler
|
msg_handler = self.handlers.message_handler
|
||||||
data = yield msg_handler.get_room_data(
|
data = yield msg_handler.get_room_data(
|
||||||
user_id=user.to_string(),
|
user_id=user.to_string(),
|
||||||
room_id=urllib.unquote(room_id),
|
room_id=room_id,
|
||||||
event_type=urllib.unquote(event_type),
|
event_type=event_type,
|
||||||
state_key=urllib.unquote(state_key),
|
state_key=state_key,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
@ -143,19 +143,18 @@ class RoomStateEventRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_PUT(self, request, room_id, event_type, state_key):
|
def on_PUT(self, request, room_id, event_type, state_key):
|
||||||
user = yield self.auth.get_user_by_req(request)
|
user = yield self.auth.get_user_by_req(request)
|
||||||
event_type = urllib.unquote(event_type)
|
|
||||||
|
|
||||||
content = _parse_json(request)
|
content = _parse_json(request)
|
||||||
|
|
||||||
event_dict = {
|
event_dict = {
|
||||||
"type": event_type,
|
"type": event_type,
|
||||||
"content": content,
|
"content": content,
|
||||||
"room_id": urllib.unquote(room_id),
|
"room_id": room_id,
|
||||||
"sender": user.to_string(),
|
"sender": user.to_string(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if state_key is not None:
|
if state_key is not None:
|
||||||
event_dict["state_key"] = urllib.unquote(state_key)
|
event_dict["state_key"] = state_key
|
||||||
|
|
||||||
msg_handler = self.handlers.message_handler
|
msg_handler = self.handlers.message_handler
|
||||||
yield msg_handler.handle_event(event_dict)
|
yield msg_handler.handle_event(event_dict)
|
||||||
@ -179,9 +178,9 @@ class RoomSendEventRestServlet(RestServlet):
|
|||||||
msg_handler = self.handlers.message_handler
|
msg_handler = self.handlers.message_handler
|
||||||
event = yield msg_handler.handle_event(
|
event = yield msg_handler.handle_event(
|
||||||
{
|
{
|
||||||
"type": urllib.unquote(event_type),
|
"type": event_type,
|
||||||
"content": content,
|
"content": content,
|
||||||
"room_id": urllib.unquote(room_id),
|
"room_id": room_id,
|
||||||
"sender": user.to_string(),
|
"sender": user.to_string(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -225,14 +224,10 @@ class JoinRoomAliasServlet(RestServlet):
|
|||||||
identifier = None
|
identifier = None
|
||||||
is_room_alias = False
|
is_room_alias = False
|
||||||
try:
|
try:
|
||||||
identifier = self.hs.parse_roomalias(
|
identifier = self.hs.parse_roomalias(room_identifier)
|
||||||
urllib.unquote(room_identifier)
|
|
||||||
)
|
|
||||||
is_room_alias = True
|
is_room_alias = True
|
||||||
except SynapseError:
|
except SynapseError:
|
||||||
identifier = self.hs.parse_roomid(
|
identifier = self.hs.parse_roomid(room_identifier)
|
||||||
urllib.unquote(room_identifier)
|
|
||||||
)
|
|
||||||
|
|
||||||
# TODO: Support for specifying the home server to join with?
|
# TODO: Support for specifying the home server to join with?
|
||||||
|
|
||||||
@ -246,7 +241,7 @@ class JoinRoomAliasServlet(RestServlet):
|
|||||||
{
|
{
|
||||||
"type": RoomMemberEvent.TYPE,
|
"type": RoomMemberEvent.TYPE,
|
||||||
"content": {"membership": Membership.JOIN},
|
"content": {"membership": Membership.JOIN},
|
||||||
"room_id": urllib.unquote(identifier.to_string()),
|
"room_id": identifier.to_string(),
|
||||||
"sender": user.to_string(),
|
"sender": user.to_string(),
|
||||||
"state_key": user.to_string(),
|
"state_key": user.to_string(),
|
||||||
}
|
}
|
||||||
@ -290,7 +285,7 @@ class RoomMemberListRestServlet(RestServlet):
|
|||||||
user = yield self.auth.get_user_by_req(request)
|
user = yield self.auth.get_user_by_req(request)
|
||||||
handler = self.handlers.room_member_handler
|
handler = self.handlers.room_member_handler
|
||||||
members = yield handler.get_room_members_as_pagination_chunk(
|
members = yield handler.get_room_members_as_pagination_chunk(
|
||||||
room_id=urllib.unquote(room_id),
|
room_id=room_id,
|
||||||
user_id=user.to_string())
|
user_id=user.to_string())
|
||||||
|
|
||||||
for event in members["chunk"]:
|
for event in members["chunk"]:
|
||||||
@ -322,7 +317,7 @@ class RoomMessageListRestServlet(RestServlet):
|
|||||||
with_feedback = "feedback" in request.args
|
with_feedback = "feedback" in request.args
|
||||||
handler = self.handlers.message_handler
|
handler = self.handlers.message_handler
|
||||||
msgs = yield handler.get_messages(
|
msgs = yield handler.get_messages(
|
||||||
room_id=urllib.unquote(room_id),
|
room_id=room_id,
|
||||||
user_id=user.to_string(),
|
user_id=user.to_string(),
|
||||||
pagin_config=pagination_config,
|
pagin_config=pagination_config,
|
||||||
feedback=with_feedback)
|
feedback=with_feedback)
|
||||||
@ -340,7 +335,7 @@ class RoomStateRestServlet(RestServlet):
|
|||||||
handler = self.handlers.message_handler
|
handler = self.handlers.message_handler
|
||||||
# Get all the current state for this room
|
# Get all the current state for this room
|
||||||
events = yield handler.get_state_events(
|
events = yield handler.get_state_events(
|
||||||
room_id=urllib.unquote(room_id),
|
room_id=room_id,
|
||||||
user_id=user.to_string(),
|
user_id=user.to_string(),
|
||||||
)
|
)
|
||||||
defer.returnValue((200, events))
|
defer.returnValue((200, events))
|
||||||
@ -355,7 +350,7 @@ class RoomInitialSyncRestServlet(RestServlet):
|
|||||||
user = yield self.auth.get_user_by_req(request)
|
user = yield self.auth.get_user_by_req(request)
|
||||||
pagination_config = PaginationConfig.from_request(request)
|
pagination_config = PaginationConfig.from_request(request)
|
||||||
content = yield self.handlers.message_handler.room_initial_sync(
|
content = yield self.handlers.message_handler.room_initial_sync(
|
||||||
room_id=urllib.unquote(room_id),
|
room_id=room_id,
|
||||||
user_id=user.to_string(),
|
user_id=user.to_string(),
|
||||||
pagin_config=pagination_config,
|
pagin_config=pagination_config,
|
||||||
)
|
)
|
||||||
@ -367,8 +362,10 @@ class RoomTriggerBackfill(RestServlet):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, request, room_id):
|
def on_GET(self, request, room_id):
|
||||||
remote_server = urllib.unquote(request.args["remote"][0])
|
remote_server = urllib.unquote(
|
||||||
room_id = urllib.unquote(room_id)
|
request.args["remote"][0]
|
||||||
|
).decode("UTF-8")
|
||||||
|
|
||||||
limit = int(request.args["limit"][0])
|
limit = int(request.args["limit"][0])
|
||||||
|
|
||||||
handler = self.handlers.federation_handler
|
handler = self.handlers.federation_handler
|
||||||
@ -408,7 +405,7 @@ class RoomMembershipRestServlet(RestServlet):
|
|||||||
{
|
{
|
||||||
"type": RoomMemberEvent.TYPE,
|
"type": RoomMemberEvent.TYPE,
|
||||||
"content": {"membership": unicode(membership_action)},
|
"content": {"membership": unicode(membership_action)},
|
||||||
"room_id": urllib.unquote(room_id),
|
"room_id": room_id,
|
||||||
"sender": user.to_string(),
|
"sender": user.to_string(),
|
||||||
"state_key": state_key,
|
"state_key": state_key,
|
||||||
}
|
}
|
||||||
@ -446,9 +443,9 @@ class RoomRedactEventRestServlet(RestServlet):
|
|||||||
{
|
{
|
||||||
"type": RoomRedactionEvent.TYPE,
|
"type": RoomRedactionEvent.TYPE,
|
||||||
"content": content,
|
"content": content,
|
||||||
"room_id": urllib.unquote(room_id),
|
"room_id": room_id,
|
||||||
"sender": user.to_string(),
|
"sender": user.to_string(),
|
||||||
"redacts": urllib.unquote(event_id),
|
"redacts": event_id,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user