emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 40629706b1f 1/2: Avoid unnecessary escaping in 'url-build-query-s


From: Eli Zaretskii
Subject: master 40629706b1f 1/2: Avoid unnecessary escaping in 'url-build-query-string'
Date: Thu, 18 Apr 2024 06:08:53 -0400 (EDT)

branch: master
commit 40629706b1ff1a2a596420dd2ac388b7e5fc656c
Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    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)
---
 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 @@ 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.
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 @@
            ("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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]