]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
urls: Also decode slashes in message IDs
authorStephen Finucane <stephen@that.guru>
Tue, 1 Aug 2023 17:05:03 +0000 (18:05 +0100)
committerStephen Finucane <stephen@that.guru>
Tue, 1 Aug 2023 17:16:42 +0000 (18:16 +0100)
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>
(cherry picked from commit ddc4c7e41a7eaec5c08296d4b441c896324f86d4)

patchwork/models.py
patchwork/views/patch.py

index deac33f84199525245ea903f88f10aaf906537ce..09c07ace5f0f2635655fe798b2fe332405181bea 100644 (file)
@@ -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,
index 9f1bb415f662b39e9755cd29b2324d347a18d410..e2c595fbaa7b65f131bfafab3c59aeb342efcc62 100644 (file)
@@ -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')