diff mbox series

urls: Also decode slashes in message IDs

Message ID 20230801171122.127948-1-stephen@that.guru
State Accepted
Headers show
Series urls: Also decode slashes in message IDs | expand

Commit Message

Stephen Finucane Aug. 1, 2023, 5:11 p.m. UTC
In commit 2653fdbb2, 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 <stephen@that.guru>
Fixes: 2653fdbb2 ("urls: Encode slashes in message IDs")
Closes: #518
Cc: Siddhesh Poyarekar <siddhesh@gotplt.org>
Cc: DJ Delorie <dj@delorie.com>
---
 patchwork/models.py      | 8 ++++++++
 patchwork/views/patch.py | 6 +++---
 2 files changed, 11 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/patchwork/models.py b/patchwork/models.py
index e828c955..67408b00 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -387,6 +387,14 @@  class EmailMixin(models.Model):
         # [1] https://datatracker.ietf.org/doc/html/rfc3986.html#section-2
         return self.url_msgid.replace('/', '%2F')
 
+    @staticmethod
+    def decode_msgid(msgid):
+        """Decode an encoded msgid.
+
+        Reverses :mod:`~url_msgid` and :mod:`~encoded_msgid` operations.
+        """
+        return f"<{msgid.replace('%2F', '/')}>"
+
     def save(self, *args, **kwargs):
         # Modifying a submission via admin interface changes '\n' newlines in
         # message content to '\r\n'. We need to fix them to avoid problems,
diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py
index 9f1bb415..e2c595fb 100644
--- a/patchwork/views/patch.py
+++ b/patchwork/views/patch.py
@@ -40,7 +40,7 @@  def patch_list(request, project_id):
 
 def patch_detail(request, project_id, msgid):
     project = get_object_or_404(Project, linkname=project_id)
-    db_msgid = f"<{msgid.replace('%2F', '/')}>"
+    db_msgid = Patch.decode_msgid(msgid)
 
     # redirect to cover letters where necessary
     try:
@@ -152,7 +152,7 @@  def patch_detail(request, project_id, msgid):
 
 
 def patch_raw(request, project_id, msgid):
-    db_msgid = '<%s>' % msgid
+    db_msgid = Patch.decode_msgid(msgid)
     project = get_object_or_404(Project, linkname=project_id)
     patch = get_object_or_404(Patch, project_id=project.id, msgid=db_msgid)
 
@@ -166,7 +166,7 @@  def patch_raw(request, project_id, msgid):
 
 
 def patch_mbox(request, project_id, msgid):
-    db_msgid = '<%s>' % msgid
+    db_msgid = Patch.decode_msgid(msgid)
     project = get_object_or_404(Project, linkname=project_id)
     patch = get_object_or_404(Patch, project_id=project.id, msgid=db_msgid)
     series_id = request.GET.get('series')