From: Kyle Meyer <kyle@kyleam.com>
To: piem@inbox.kyleam.com
Subject: [PATCH 1/2] Escape message IDs when constructing URLs
Date: Sat, 19 Sep 2020 00:46:38 -0400 [thread overview]
Message-ID: <20200919044639.26871-2-kyle@kyleam.com> (raw)
In-Reply-To: <20200919044639.26871-1-kyle@kyleam.com>
Message IDs can include characters that must escaped before being
included in the path part of public-inbox URLs. Add a variant of
url-hexify-string that uses the same set of characters as
public-inbox's mid_escape().
---
piem-b4.el | 2 +-
piem.el | 14 ++++++++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/piem-b4.el b/piem-b4.el
index b77d111..596e563 100644
--- a/piem-b4.el
+++ b/piem-b4.el
@@ -66,7 +66,7 @@ (defun piem-b4--get-am-files (mid coderepo args)
(mid (piem-mid))
(buffer (condition-case nil
(piem-download-and-decompress
- (concat url mid "/t.mbox.gz"))
+ (concat url (piem-escape-mid mid) "/t.mbox.gz"))
(error nil))))
(with-current-buffer buffer
(write-region nil nil mbox-thread))
diff --git a/piem.el b/piem.el
index dd2b30e..7c6ca6f 100644
--- a/piem.el
+++ b/piem.el
@@ -261,7 +261,7 @@ (defun piem-message-link-re (url &optional mid)
non-nil, make the match specific for that message."
(rx-to-string
`(and ,(piem--ensure-trailing-slash url)
- (group ,(or mid
+ (group ,(or (and mid (piem-escape-mid mid))
'(one-or-more (not (any "/" "\n")))))
"/" (group (zero-or-one
(or "raw"
@@ -403,6 +403,16 @@ (defun piem-am-ready-mbox ()
\f
;;;; Download helpers
+(defconst piem--unreserved-chars
+ (append url-unreserved-chars
+ ;; These extra characters follow what's used by
+ ;; public-inbox's mid_escape().
+ (list ?! ?$ ?& ?' ?\( ?\) ?* ?+ ?, ?= ?: ?\; ?@)))
+
+(defun piem-escape-mid (mid)
+ "Escape MID for use in path part of a public-inbox URL."
+ (url-hexify-string mid piem--unreserved-chars))
+
(defvar piem--has-gunzip)
(defun piem-check-gunzip ()
"Return non-nil if gunzip is available."
@@ -500,7 +510,7 @@ (defun piem-inject-thread-into-maildir (mid &optional message-only)
(when-let ((url (concat (or (piem-inbox-get :url)
(user-error
"Could not find inbox URL for current buffer"))
- mid
+ (piem-escape-mid mid)
(if message-only "/raw" "/t.mbox.gz")))
(buffer (url-retrieve-synchronously url 'silent)))
(unwind-protect
--
2.28.0
next prev parent reply other threads:[~2020-09-19 4:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-19 4:46 [PATCH 0/2] URL escaping fixes Kyle Meyer
2020-09-19 4:46 ` Kyle Meyer [this message]
2020-09-19 4:46 ` [PATCH 2/2] Unescape message IDs extracted from URLs Kyle Meyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://git.kyleam.com/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200919044639.26871-2-kyle@kyleam.com \
--to=kyle@kyleam.com \
--cc=piem@inbox.kyleam.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.kyleam.com/piem/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).