Skip to content

Commit 9838450

Browse files
committed
urls: Also decode slashes in message IDs
In commit 2653fdb, we started encoding slashes in message IDs presented to users. This allowed us to support message IDs containing slashes, which are allowed per the RFC and have been seen in the wild. However, we continue to store the original unencoded message IDs in the database and unfortunately we neglected to reverse the decoding in the functions for downloading patch diffs and mboxes. Address this now. Signed-off-by: Stephen Finucane <[email protected]> Fixes: 2653fdb ("urls: Encode slashes in message IDs") Closes: #518 Cc: Siddhesh Poyarekar <[email protected]> Cc: DJ Delorie <[email protected]> (cherry picked from commit ddc4c7e)
1 parent f8226ff commit 9838450

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

patchwork/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,14 @@ def encoded_msgid(self):
387387
# [1] https://datatracker.ietf.org/doc/html/rfc3986.html#section-2
388388
return self.url_msgid.replace('/', '%2F')
389389

390+
@staticmethod
391+
def decode_msgid(msgid):
392+
"""Decode an encoded msgid.
393+
394+
Reverses :mod:`~url_msgid` and :mod:`~encoded_msgid` operations.
395+
"""
396+
return f"<{msgid.replace('%2F', '/')}>"
397+
390398
def save(self, *args, **kwargs):
391399
# Modifying a submission via admin interface changes '\n' newlines in
392400
# message content to '\r\n'. We need to fix them to avoid problems,

patchwork/views/patch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def patch_list(request, project_id):
4040

4141
def patch_detail(request, project_id, msgid):
4242
project = get_object_or_404(Project, linkname=project_id)
43-
db_msgid = f"<{msgid.replace('%2F', '/')}>"
43+
db_msgid = Patch.decode_msgid(msgid)
4444

4545
# redirect to cover letters where necessary
4646
try:
@@ -152,7 +152,7 @@ def patch_detail(request, project_id, msgid):
152152

153153

154154
def patch_raw(request, project_id, msgid):
155-
db_msgid = '<%s>' % msgid
155+
db_msgid = Patch.decode_msgid(msgid)
156156
project = get_object_or_404(Project, linkname=project_id)
157157
patch = get_object_or_404(Patch, project_id=project.id, msgid=db_msgid)
158158

@@ -166,7 +166,7 @@ def patch_raw(request, project_id, msgid):
166166

167167

168168
def patch_mbox(request, project_id, msgid):
169-
db_msgid = '<%s>' % msgid
169+
db_msgid = Patch.decode_msgid(msgid)
170170
project = get_object_or_404(Project, linkname=project_id)
171171
patch = get_object_or_404(Patch, project_id=project.id, msgid=db_msgid)
172172
series_id = request.GET.get('series')

0 commit comments

Comments
 (0)