discussion and development of piem
 help / color / mirror / Atom feed
* [PATCH 1/2] Escape message IDs when constructing URLs
  2020-09-19  4:46 [PATCH 0/2] URL escaping fixes Kyle Meyer
@ 2020-09-19  4:46 ` Kyle Meyer
  0 siblings, 0 replies; only message in thread
From: Kyle Meyer @ 2020-09-19  4:46 UTC (permalink / raw)
  To: piem

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-19  4:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-19  4:46 [PATCH 0/2] URL escaping fixes Kyle Meyer
2020-09-19  4:46 ` [PATCH 1/2] Escape message IDs when constructing URLs Kyle Meyer

discussion and development of piem

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.kyleam.com/piem/0 piem/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 piem piem/ https://inbox.kyleam.com/piem \
		piem@inbox.kyleam.com
	public-inbox-index piem

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.piem


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git