commit 686bd788243ef38951c3c529d4c67c3ad766f417 Author: Michael Brand Date: Sat Nov 16 16:13:57 2013 +0100 Hyperlink: Use url-encode-url for browse-url * lisp/org.el (org-open-at-point): When available (Emacs 24.3) use `url-encode-url' instead of `org-link-escape-browser'. * testing/lisp/test-org.el (test-org/org-link-escape-url-with-escaped-char): Substitute repeated literal string with constant. (test-org/org-link-escape-chars-browser): Extend test coverage with `url-encode-url' and with "query="-space as plus sign or space. diff --git a/lisp/org.el b/lisp/org.el index a3c1958..aa91ffc 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -10468,11 +10468,20 @@ application the system uses for this file type." (apply cmd (nreverse args1)))) ((member type '("http" "https" "ftp" "news")) - (browse-url (concat type ":" (org-link-escape-browser path)))) + ;; see `ert-deftest' + ;; `test-org/org-link-escape-chars-browser' + (browse-url + (if (fboundp 'url-encode-url) + (url-encode-url (concat type ":" path)) + (org-link-escape-browser (concat type ":" path))))) ((string= type "doi") - (browse-url (concat org-doi-server-url - (org-link-escape-browser path)))) + ;; see `ert-deftest' + ;; `test-org/org-link-escape-chars-browser' + (browse-url + (if (fboundp 'url-encode-url) + (url-encode-url (concat org-doi-server-url path)) + (org-link-escape-browser (concat org-doi-server-url path))))) ((member type '("message")) (browse-url (concat type ":" path))) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index f4672eb..084e95d 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -552,21 +552,53 @@ (ert-deftest test-org/org-link-escape-url-with-escaped-char () "Escape and unescape a URL that includes an escaped char. http://article.gmane.org/gmane.emacs.orgmode/21459/" - (should - (string= - "http://some.host.com/form?&id=blah%2Bblah25" - (org-link-unescape - (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25"))))) + (let ((a "http://some.host.com/form?&id=blah%2Bblah25")) + (should (string= a (org-link-unescape (org-link-escape a)))))) (ert-deftest test-org/org-link-escape-chars-browser () - "Escape a URL to pass to `browse-url'." - (should - (string= - (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query=" - "%22Release%208.2%22&idxname=emacs-orgmode") - (org-link-escape-browser - (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query=" - "\"Release 8.2\"&idxname=emacs-orgmode"))))) + "Escape a URL before passing it to `browse-url'. + +This test is to ensure that `org-open-at-point' on the Org links + + [[http://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emacs-orgmode&query=%252Bsubject:\"Release+8.2\"]] + [[http://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emacs-orgmode&query=%252Bsubject:\"Release 8.2\"]] + +will open a browser with +subject:\"Release 8.2\" in the query +field." + + ;; Each string argument passed to `url-encode-url' or + ;; `org-link-escape-browser' in the tests below (or when + ;; `org-open-at-point' is used in an Org buffer) looks like after + ;; the Org link from the docstring has been unescaped by + ;; `org-link-unescape' in `org-open-at-point' + (let ((query (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?" + "idxname=emacs-orgmode&query=")) + (plus "%2Bsubject:\"Release+8.2\"") ; "query="-space as plus sign + (space "%2Bsubject:\"Release 8.2\"")) ; "query="-space as space + + ;; This is the behavior of `org-open-at-point' when used together + ;; with an Emacs 24.3 or later where `url-encode-url' is available + (when (fboundp 'url-encode-url) + ;; "query="-space as plus sign + (should (string= (concat query "%2Bsubject:%22Release+8.2%22") + (url-encode-url (concat query plus)))) + ;; "query="-space as space + (should (string= (concat query "%2Bsubject:%22Release%208.2%22") + (url-encode-url (concat query space))))) + + ;; The %252B below returned from `org-link-escape-browser' is not + ;; desired and not working with some browser/OS but tested here to + ;; document what happens when the fallback to + ;; `org-link-escape-browser' in `org-open-at-point' is in use, + ;; which is the legacy behavior of `org-open-at-point' when used + ;; together with an Emacs before version 24.3 + ;; + ;; "query="-space as plus sign + (should (string= (concat query "%252Bsubject:%22Release+8.2%22") + (org-link-escape-browser (concat query plus)))) + ;; "query="-space as space + (should (string= (concat query "%252Bsubject:%22Release%208.2%22") + (org-link-escape-browser (concat query space))))))