aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2017-05-10 03:34:16 +0300
committerDmitry Gutov2017-05-10 03:34:58 +0300
commit17e540aa428c5392f7a9b4c1f7495bac8a8fe5da (patch)
treed720eb99d0b8907f4567dd9c72151dcfa1331b64
parent58326f0f117b229b690023d3851a00d876a7aca6 (diff)
downloademacs-17e540aa428c5392f7a9b4c1f7495bac8a8fe5da.tar.gz
emacs-17e540aa428c5392f7a9b4c1f7495bac8a8fe5da.zip
Simplify url-encode-url and add a test
* lisp/url/url-util.el (url-encode-url): Simplify. url-generic-parse-url copes with multibyte strings just fine (https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24117#185). * test/lisp/url/url-parse-tests.el (url-generic-parse-url/multibyte-host-and-path): New test.
-rw-r--r--lisp/url/url-util.el11
-rw-r--r--test/lisp/url/url-parse-tests.el5
2 files changed, 6 insertions, 10 deletions
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el
index 46d2d8ce5ff..9897dea9c7f 100644
--- a/lisp/url/url-util.el
+++ b/lisp/url/url-util.el
@@ -450,13 +450,10 @@ This function also performs URI normalization, e.g. converting
450the scheme to lowercase if it is uppercase. Apart from 450the scheme to lowercase if it is uppercase. Apart from
451normalization, if URL is already URI-encoded, this function 451normalization, if URL is already URI-encoded, this function
452should return it unchanged." 452should return it unchanged."
453 (if (multibyte-string-p url)
454 (setq url (encode-coding-string url 'utf-8)))
455 (let* ((obj (url-generic-parse-url url)) 453 (let* ((obj (url-generic-parse-url url))
456 (user (url-user obj)) 454 (user (url-user obj))
457 (pass (url-password obj)) 455 (pass (url-password obj))
458 (host (url-host obj)) 456 (path-and-query (url-path-and-query obj))
459 (path-and-query (url-path-and-query obj))
460 (path (car path-and-query)) 457 (path (car path-and-query))
461 (query (cdr path-and-query)) 458 (query (cdr path-and-query))
462 (frag (url-target obj))) 459 (frag (url-target obj)))
@@ -464,12 +461,6 @@ should return it unchanged."
464 (setf (url-user obj) (url-hexify-string user))) 461 (setf (url-user obj) (url-hexify-string user)))
465 (if pass 462 (if pass
466 (setf (url-password obj) (url-hexify-string pass))) 463 (setf (url-password obj) (url-hexify-string pass)))
467 ;; No special encoding for IPv6 literals.
468 (and host
469 (not (string-match "\\`\\[.*\\]\\'" host))
470 (setf (url-host obj)
471 (decode-coding-string (url-host obj) 'utf-8)))
472
473 (if path 464 (if path
474 (setq path (url-hexify-string path url-path-allowed-chars))) 465 (setq path (url-hexify-string path url-path-allowed-chars)))
475 (if query 466 (if query
diff --git a/test/lisp/url/url-parse-tests.el b/test/lisp/url/url-parse-tests.el
index 05da7280aa2..fd8abb0a5e5 100644
--- a/test/lisp/url/url-parse-tests.el
+++ b/test/lisp/url/url-parse-tests.el
@@ -162,6 +162,11 @@
162 (should (equal (url-generic-parse-url "#") (url-parse-make-urlobj nil nil nil nil nil "" "" nil nil))) 162 (should (equal (url-generic-parse-url "#") (url-parse-make-urlobj nil nil nil nil nil "" "" nil nil)))
163 (should (equal (url-generic-parse-url "#foo") (url-parse-make-urlobj nil nil nil nil nil "" "foo" nil nil)))) 163 (should (equal (url-generic-parse-url "#foo") (url-parse-make-urlobj nil nil nil nil nil "" "foo" nil nil))))
164 164
165(ert-deftest url-generic-parse-url/multibyte-host-and-path ()
166 (should (equal (url-generic-parse-url "http://банки.рф/фыва/")
167 (url-parse-make-urlobj "http" nil nil "банки.рф" nil
168 "/фыва/" nil nil t))))
169
165(provide 'url-parse-tests) 170(provide 'url-parse-tests)
166 171
167;;; url-parse-tests.el ends here 172;;; url-parse-tests.el ends here