From 17e540aa428c5392f7a9b4c1f7495bac8a8fe5da Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Wed, 10 May 2017 03:34:16 +0300 Subject: [PATCH] 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. --- lisp/url/url-util.el | 11 +---------- test/lisp/url/url-parse-tests.el | 5 +++++ 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 the scheme to lowercase if it is uppercase. Apart from normalization, if URL is already URI-encoded, this function should return it unchanged." - (if (multibyte-string-p url) - (setq url (encode-coding-string url 'utf-8))) (let* ((obj (url-generic-parse-url url)) (user (url-user obj)) (pass (url-password obj)) - (host (url-host obj)) - (path-and-query (url-path-and-query obj)) + (path-and-query (url-path-and-query obj)) (path (car path-and-query)) (query (cdr path-and-query)) (frag (url-target obj))) @@ -464,12 +461,6 @@ should return it unchanged." (setf (url-user obj) (url-hexify-string user))) (if pass (setf (url-password obj) (url-hexify-string pass))) - ;; No special encoding for IPv6 literals. - (and host - (not (string-match "\\`\\[.*\\]\\'" host)) - (setf (url-host obj) - (decode-coding-string (url-host obj) 'utf-8))) - (if path (setq path (url-hexify-string path url-path-allowed-chars))) (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 @@ (should (equal (url-generic-parse-url "#") (url-parse-make-urlobj nil nil nil nil nil "" "" nil nil))) (should (equal (url-generic-parse-url "#foo") (url-parse-make-urlobj nil nil nil nil nil "" "foo" nil nil)))) +(ert-deftest url-generic-parse-url/multibyte-host-and-path () + (should (equal (url-generic-parse-url "http://банки.рф/фыва/") + (url-parse-make-urlobj "http" nil nil "банки.рф" nil + "/фыва/" nil nil t)))) + (provide 'url-parse-tests) ;;; url-parse-tests.el ends here -- 2.39.2