Subject: bug#24694: Document url--allow-chars for external use?

From: Hong Xu <[email-masked]>
Date: Fri, 11 Oct 2019 19:21:34 -0700

On 10/11/19 7:32 AM, Robert Pluim wrote:
>>>>>> On Fri, 11 Oct 2019 15:38:03 +0300, Eli Zaretskii <[email-masked]> said:
> 
>      >> From: Hong Xu <[email-masked]>
>      >> Cc: [email-masked]
>      >> Date: Fri, 4 Oct 2019 12:31:27 -0700
>      >>
>      >> > Make url-hexify-string accept a list of allowed chars.
>      >> >
>      >> > 	* url-util.el (url-hexify-string): Accept a list of allowed chars.
>      >> > 	* url.texi (URI Encoding): Update url-hexify-string doc and index improvements.
>      >> >
>      >>
>      >> It's been a few years... I'm wondering whether this patch is still interesting?
> 
>      Eli> I think it is, yes.  Can you send a patch relative to the current
>      Eli> master branch?
> 
> Api nit: if the first argument is going to be a list or a vector, you
> could just keep one argument and check 'vectorp'.
> 

Thanks, I've updated the patch as attached.
>From 4f56c4081f44ab04e3095b5f3b5332d5c3eb1cdf Mon Sep 17 00:00:00 2001
From: Hong Xu <[email-masked]>
Date: Fri, 11 Oct 2019 19:17:23 -0700
Subject: [PATCH] Make url-hexify-string accept a list of allowed chars.

* url-util.el (url-hexify-string): Accept a list of allowed chars.
* url.texi (URI Encoding): Update url-hexify-string doc and index
improvements.
---
 doc/misc/url.texi    |  4 ++++
 lisp/url/url-util.el | 10 +++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/doc/misc/url.texi b/doc/misc/url.texi
index e72d9bfe3d2e..ff6c547bec1e 100644
--- a/doc/misc/url.texi
+++ b/doc/misc/url.texi
@@ -221,6 +221,7 @@ URI Encoding
 @section URI Encoding
 
 @cindex percent encoding
+@findex url-generic-parse-url
   The @code{url-generic-parse-url} parser does not obey RFC 3986 in
 one respect: it allows non-@acronym{ASCII} characters in URI strings.
 
@@ -233,6 +234,7 @@ URI Encoding
 @acronym{ASCII} characters must also be percent encoded when they
 appear in URI components.)
 
+@findex url-encode-url
   The function @code{url-encode-url} can be used to convert a URI
 string containing arbitrary characters to one that is properly
 percent-encoded in accordance with RFC 3986.
@@ -244,6 +246,8 @@ URI Encoding
 previously uppercase.
 @end defun
 
+@findex url-hexify-string
+@findex url-unhex-string
   To convert between a string containing arbitrary characters and a
 percent-encoded all-@acronym{ASCII} string, use the functions
 @code{url-hexify-string} and @code{url-unhex-string}:
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el
index a390723e73dc..7abd5c216eeb 100644
--- a/lisp/url/url-util.el
+++ b/lisp/url/url-util.el
@@ -395,9 +395,13 @@ url-hexify-string
 
 The allowed characters are specified by ALLOWED-CHARS.  If this
 argument is nil, the list `url-unreserved-chars' determines the
-allowed characters.  Otherwise, ALLOWED-CHARS should be a vector
-whose Nth element is non-nil if character N is allowed."
-  (unless allowed-chars
+allowed characters.  Otherwise, ALLOWED-CHARS should be either a
+vector whose Nth element is non-nil if character N is allowed or
+a list of allowed chars.
+"
+  (if allowed-chars
+      (unless (vectorp allowed-chars)
+        (setq allowed-chars (url--allowed-chars allowed-chars)))
     (setq allowed-chars (url--allowed-chars url-unreserved-chars)))
   (mapconcat (lambda (byte)
 	       (if (aref allowed-chars byte)
-- 
2.20.1