diff options
| author | Hong Xu | 2019-10-14 06:46:47 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-10-14 06:46:47 +0200 |
| commit | 9aa13cd4beccfe41e8f4930cb029bd60e7788e93 (patch) | |
| tree | 93968ba332ad4623b8251d081175641f7146c1dc | |
| parent | 8aeba640460adbad283d4a18f91cce8e0364c40d (diff) | |
| download | emacs-9aa13cd4beccfe41e8f4930cb029bd60e7788e93.tar.gz emacs-9aa13cd4beccfe41e8f4930cb029bd60e7788e93.zip | |
Make url-hexify-string accept a list of allowed chars (bug#26469)
* lisp/url/url-util.el (url-hexify-string): Accept a list of allowed
chars.
* doc/misc/url.texi (URI Encoding): Update url-hexify-string doc and
index improvements (bug#24694).
| -rw-r--r-- | doc/misc/url.texi | 8 | ||||
| -rw-r--r-- | lisp/url/url-util.el | 9 |
2 files changed, 12 insertions, 5 deletions
diff --git a/doc/misc/url.texi b/doc/misc/url.texi index e72d9bfe3d2..79dead185dd 100644 --- a/doc/misc/url.texi +++ b/doc/misc/url.texi | |||
| @@ -221,6 +221,7 @@ URI's @var{port} slot is @code{nil}. | |||
| 221 | @section URI Encoding | 221 | @section URI Encoding |
| 222 | 222 | ||
| 223 | @cindex percent encoding | 223 | @cindex percent encoding |
| 224 | @findex url-generic-parse-url | ||
| 224 | The @code{url-generic-parse-url} parser does not obey RFC 3986 in | 225 | The @code{url-generic-parse-url} parser does not obey RFC 3986 in |
| 225 | one respect: it allows non-@acronym{ASCII} characters in URI strings. | 226 | one respect: it allows non-@acronym{ASCII} characters in URI strings. |
| 226 | 227 | ||
| @@ -233,6 +234,7 @@ then percent encoded to @samp{%D3%A7}. (Certain ``reserved'' | |||
| 233 | @acronym{ASCII} characters must also be percent encoded when they | 234 | @acronym{ASCII} characters must also be percent encoded when they |
| 234 | appear in URI components.) | 235 | appear in URI components.) |
| 235 | 236 | ||
| 237 | @findex url-encode-url | ||
| 236 | The function @code{url-encode-url} can be used to convert a URI | 238 | The function @code{url-encode-url} can be used to convert a URI |
| 237 | string containing arbitrary characters to one that is properly | 239 | string containing arbitrary characters to one that is properly |
| 238 | percent-encoded in accordance with RFC 3986. | 240 | percent-encoded in accordance with RFC 3986. |
| @@ -244,6 +246,8 @@ e.g., converting the scheme component to lowercase if it was | |||
| 244 | previously uppercase. | 246 | previously uppercase. |
| 245 | @end defun | 247 | @end defun |
| 246 | 248 | ||
| 249 | @findex url-hexify-string | ||
| 250 | @findex url-unhex-string | ||
| 247 | To convert between a string containing arbitrary characters and a | 251 | To convert between a string containing arbitrary characters and a |
| 248 | percent-encoded all-@acronym{ASCII} string, use the functions | 252 | percent-encoded all-@acronym{ASCII} string, use the functions |
| 249 | @code{url-hexify-string} and @code{url-unhex-string}: | 253 | @code{url-hexify-string} and @code{url-unhex-string}: |
| @@ -263,8 +267,8 @@ The allowed characters are specified by @var{allowed-chars}. If this | |||
| 263 | argument is @code{nil}, the allowed characters are those specified as | 267 | argument is @code{nil}, the allowed characters are those specified as |
| 264 | @dfn{unreserved characters} by RFC 3986 (see the variable | 268 | @dfn{unreserved characters} by RFC 3986 (see the variable |
| 265 | @code{url-unreserved-chars}). Otherwise, @var{allowed-chars} should | 269 | @code{url-unreserved-chars}). Otherwise, @var{allowed-chars} should |
| 266 | be a vector whose @var{n}-th element is non-@code{nil} if character | 270 | be either a list of allowed chars, or a vector whose Nth element is |
| 267 | @var{n} is allowed. | 271 | non-nil if character N is allowed. |
| 268 | @end defun | 272 | @end defun |
| 269 | 273 | ||
| 270 | @defun url-unhex-string string &optional allow-newlines | 274 | @defun url-unhex-string string &optional allow-newlines |
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el index a390723e73d..223a6ba9829 100644 --- a/lisp/url/url-util.el +++ b/lisp/url/url-util.el | |||
| @@ -395,9 +395,12 @@ string: \"%\" followed by two upper-case hex digits. | |||
| 395 | 395 | ||
| 396 | The allowed characters are specified by ALLOWED-CHARS. If this | 396 | The allowed characters are specified by ALLOWED-CHARS. If this |
| 397 | argument is nil, the list `url-unreserved-chars' determines the | 397 | argument is nil, the list `url-unreserved-chars' determines the |
| 398 | allowed characters. Otherwise, ALLOWED-CHARS should be a vector | 398 | allowed characters. Otherwise, ALLOWED-CHARS should be either a |
| 399 | whose Nth element is non-nil if character N is allowed." | 399 | list of allowed chars, or a vector whose Nth element is non-nil |
| 400 | (unless allowed-chars | 400 | if character N is allowed." |
| 401 | (if allowed-chars | ||
| 402 | (unless (vectorp allowed-chars) | ||
| 403 | (setq allowed-chars (url--allowed-chars allowed-chars))) | ||
| 401 | (setq allowed-chars (url--allowed-chars url-unreserved-chars))) | 404 | (setq allowed-chars (url--allowed-chars url-unreserved-chars))) |
| 402 | (mapconcat (lambda (byte) | 405 | (mapconcat (lambda (byte) |
| 403 | (if (aref allowed-chars byte) | 406 | (if (aref allowed-chars byte) |