1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-24 07:20:37 +00:00

Avoid unnecessary escaping in 'url-build-query-string'

* lisp/url/url-util.el (url-query-key-value-allowed-chars):
New defconst.
(url-build-query-string): Use it to escape only those
characters that need it in keys and values.
* test/lisp/url/url-util-tests.el (url-util-tests): Add
new test cases.  (Bug#70312)
This commit is contained in:
Dagfinn Ilmari Mannsåker 2024-04-09 15:02:45 +01:00 committed by Eli Zaretskii
parent 3c4f6c78b4
commit 40629706b1
2 changed files with 16 additions and 2 deletions

View File

@ -268,7 +268,8 @@ instead of just \"key\" as in the example above."
(lambda (key-vals)
(let ((escaped
(mapcar (lambda (sym)
(url-hexify-string (format "%s" sym))) key-vals)))
(url-hexify-string (format "%s" sym) url-query-key-value-allowed-chars))
key-vals)))
(mapconcat (lambda (val)
(let ((vprint (format "%s" val))
(eprint (format "%s" (car escaped))))
@ -410,6 +411,15 @@ These characters are specified in RFC 3986, Appendix A.")
"Allowed-character byte mask for the query segment of a URI.
These characters are specified in RFC 3986, Appendix A.")
(defconst url-query-key-value-allowed-chars
(let ((vec (copy-sequence url-query-allowed-chars)))
(aset vec ?= nil)
(aset vec ?& nil)
(aset vec ?\; nil)
vec)
"Allowed-charcter byte mask for keys and values in the query segment of a URI.
url-query-allowed-chars minus '=', '&', and ';'.")
;;;###autoload
(defun url-encode-url (url)
"Return a properly URI-encoded version of URL.

View File

@ -32,7 +32,11 @@
("key1=val1;key2=val2;key3=val1;key3=val2;key4;key5"
((key1 "val1") (key2 val2) (key3 val1 val2) ("key4") (key5 "")) t)
("key1=val1;key2=val2;key3=val1;key3=val2;key4=;key5="
((key1 val1) (key2 val2) ("key3" val1 val2) (key4) (key5 "")) t t)))
((key1 val1) (key2 val2) ("key3" val1 val2) (key4) (key5 "")) t t)
("key1=val/slash;key2=val%3Bsemi;key3=val%26amp;key4=val%3Deq"
((key1 "val/slash") (key2 "val;semi") (key3 "val&amp") (key4 "val=eq")) t)
("key%3Deq=val1;key%3Bsemi=val2;key%26amp=val3"
(("key=eq" val1) ("key;semi" val2) ("key&amp" val3)) t)))
test)
(while tests
(setq test (car tests)