From: "Dagfinn Ilmari Mannsåker" <ilmari@ilmari.org>
To: 70312@debbugs.gnu.org
Subject: bug#70312: [PATCH v2] Avoid unnecessary escaping in url-build-query-string
Date: Tue, 09 Apr 2024 17:41:07 +0100 [thread overview]
Message-ID: <87zfu2ij4s.fsf@wibble.ilmari.org> (raw)
In-Reply-To: <8734ruk3tf.fsf@wibble.ilmari.org>
[-- Attachment #1: Type: text/plain, Size: 403 bytes --]
Hi again,
I realised I'd forgotten to add tests, and that made me realise that
url-query-allowed-chars is not correct for this, since that also
contains '=', '&', and ';'. So here's an updated patch, which creates a
new url-query-key-value-allowed-chars constant, which is
url-query-allowed-chars minus the aforementioned three chars, and adds
tests covering that, for both keys and values.
- ilmari
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v2-0001-Avoid-unnecessary-escaping-in-url-build-query-str.patch --]
[-- Type: text/x-diff, Size: 2898 bytes --]
From 89db0a1226d8d7cca1846e9c737d4a67c971ec75 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Tue, 9 Apr 2024 15:02:45 +0100
Subject: [PATCH v2] Avoid unnecessary escaping in url-build-query-string
* lisp/url/url-util.el (url-build-query-string):
Create a new url-query-key-value-allowed-chars constant and pass that to
url-hexify-string to avoid unnecessarily escaping characters that don't
need to be escaped in query string keys and values.
* test/lisp/url/url-util-tests.el (url-util-tests):
Add test cases.
---
lisp/url/url-util.el | 12 +++++++++++-
test/lisp/url/url-util-tests.el | 6 +++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el
index 5f45b98c7a5..f063efe18a6 100644
--- a/lisp/url/url-util.el
+++ b/lisp/url/url-util.el
@@ -268,7 +268,8 @@ url-build-query-string
(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 @@ url-query-allowed-chars
"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.
diff --git a/test/lisp/url/url-util-tests.el b/test/lisp/url/url-util-tests.el
index 133aa0ffd88..c6246d69a2a 100644
--- a/test/lisp/url/url-util-tests.el
+++ b/test/lisp/url/url-util-tests.el
@@ -32,7 +32,11 @@ url-util-tests
("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&") (key4 "val=eq")) t)
+ ("key%3Deq=val1;key%3Bsemi=val2;key%26amp=val3"
+ (("key=eq" val1) ("key;semi" val2) ("key&" val3)) t)))
test)
(while tests
(setq test (car tests)
--
2.39.2
next prev parent reply other threads:[~2024-04-09 16:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-09 14:29 bug#70312: [PATCH] Avoid unnecessary escaping in url-build-query-string Dagfinn Ilmari Mannsåker
2024-04-09 16:41 ` Dagfinn Ilmari Mannsåker [this message]
2024-04-18 10:10 ` bug#70312: [PATCH v2] " Eli Zaretskii
2024-05-19 11:18 ` Philip Kaludercic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zfu2ij4s.fsf@wibble.ilmari.org \
--to=ilmari@ilmari.org \
--cc=70312@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).