Kyle Meyer writes:

> For public-inbox URLs, there is one character that needs to be escaped:
> "/" with "%2F" (see <https://yhetil.org/guix-devel/_/text/help/>).

Correcting myself: I shouldn't take that help page as a complete
description of what needs to be escaped for public-inbox URLs.  It'd be
better to look at what public-inbox's code does itself, particularly
when it generates the path component of the URL for its Archived-At
header.  It feeds the message ID through this function:

,----[ lib/PublicInbox/MID.pm ]
| # RFC3986, section 3.3:
| sub MID_ESC () { '^A-Za-z0-9\-\._~!\$\&\';\(\)\*\+,;=:@' }
| sub mid_escape ($) { uri_escape_utf8($_[0], MID_ESC) }
`----

That code came with 9d1e5fad (www: do not unecessarily escape some chars
in paths, 2016-08-14).

So, if you want to perform the same escaping for your custom Elisp
function that generates public-inbox URLs, you can do something like
this:

    (let ((unreserved-chars
           (append url-unreserved-chars
                   '(?! ?$ ?& ?' ?\( ?\) ?* ?+ ?, ?= ?: ?@ ?\;))))
      (url-hexify-string "8...@e.com" unreserved-chars)  ; => "8...@e.com"
      (url-hexify-string "8...@e.com" unreserved-chars)  ; => "8...@e.com"
      (url-hexify-string "8/@e.com" unreserved-chars)) ; => "8...@e.com"

Or, if you don't mind the unnecessary escaping (particularly of "@"),
you can just use url-hexify-string with the default set of unreserved
characters.

Reply via email to