summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brand <michael.ch.brand@gmail.com>2014-02-19 20:49:21 +0100
committerMichael Brand <michael.ch.brand@gmail.com>2014-02-19 20:49:21 +0100
commit54e3009d7319e4bece967be165061331070635e5 (patch)
treed707e32d6a899fda98fd5e170f3bdde773414812
parent49d69b739f6b13e7840b64e6739e15d12b6c98e6 (diff)
downloadorg-mode-54e3009d7319e4bece967be165061331070635e5.tar.gz
Fix escaping of more links in HTML export
* lisp/org.el (org-link-escape-chars): Extend docstring. (org-link-escape-chars-browser): Mention in docstring that it will become a candidate for removal. (org-link-escape-browser): Mention in docstring that it will become a candidate for removal. (org-open-at-point): Move `url-encode-url' and comments into `org-link-escape-browser'. * lisp/ox-html.el (org-html-link): Make use of `org-link-escape-browser' like `org-open-at-point'. * testing/lisp/test-org.el (test-org/org-link-escape-chars-browser): Mention in docstring that it will become a candidate for removal.
-rw-r--r--lisp/org.el60
-rw-r--r--lisp/ox-html.el5
-rw-r--r--testing/lisp/test-org.el7
3 files changed, 38 insertions, 34 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 37e91cc..ac53e56 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9812,14 +9812,17 @@ according to FMT (default from `org-email-link-description-format')."
(defconst org-link-escape-chars
;;%20 %2B %3B %3D %5B %5D
'(?\ ?\+ ?\; ?\= ?\[ ?\])
- "List of characters that should be escaped in link.
+ "List of characters that should be escaped in a link when stored to Org.
This is the list that is used for internal purposes.")
(defconst org-link-escape-chars-browser
;;%20 %22
'(?\ ?\")
- "List of escapes for characters that are problematic in links.
-This is the list that is used before handing over to the browser.")
+ "List of characters to be escaped before handing over to the browser.
+If you consider using this constant then you probably want to use
+the function `org-link-escape-browser' instead. See there why
+this constant is a candidate to be removed once Org drops support
+for Emacs 24.1 and 24.2.")
(defun org-link-escape (text &optional table merge)
"Return percent escaped representation of TEXT.
@@ -9848,11 +9851,27 @@ If optional argument MERGE is set, merge TABLE into
(char-to-string char))) text ""))
(defun org-link-escape-browser (text)
- (if (org-string-match-p
- (concat "[[:nonascii:]" org-link-escape-chars-browser "]")
- text)
- (org-link-escape text org-link-escape-chars-browser)
- text))
+ "Escape some characters before handing over to the browser.
+This function is a candidate to be removed together with the
+constant `org-link-escape-chars-browser' once Org drops support
+for Emacs 24.1 and 24.2. All calls to this function will have to
+be replaced with `url-encode-url' which is available since Emacs
+24.3.1."
+ ;; Example with the Org link
+ ;; [[http://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emacs-orgmode&query=%252Bsubject:"Release+8.2"]]
+ ;; to open the browser with +subject:"Release 8.2" filled into the
+ ;; query field: In this case the variable TEXT contains the
+ ;; unescaped [...]=%2Bsubject:"Release+8.2". Then `url-encode-url'
+ ;; converts correctly to [...]=%2Bsubject:%22Release+8.2%22 or
+ ;; `org-link-escape' with `org-link-escape-chars-browser' converts
+ ;; wrongly to [...]=%252Bsubject:%22Release+8.2%22.
+ (if (fboundp 'url-encode-url)
+ (url-encode-url text)
+ (if (org-string-match-p
+ (concat "[[:nonascii:]" org-link-escape-chars-browser "]")
+ text)
+ (org-link-escape text org-link-escape-chars-browser)
+ text)))
(defun org-link-unescape (str)
"Unhex hexified Unicode strings as returned from the JavaScript function
@@ -10577,29 +10596,12 @@ application the system uses for this file type."
(apply cmd (nreverse args1))))
((member type '("http" "https" "ftp" "news"))
- ;; In the example of the http Org link
- ;; [[http://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emacs-orgmode&query=%252Bsubject:"Release+8.2"]]
- ;; to open a browser with +subject:"Release 8.2" in the
- ;; query field the variable `path' contains
- ;; [...]=%2Bsubject:"Release+8.2", `url-encode-url'
- ;; converts correct to [...]=%2Bsubject:%22Release+8.2%22
- ;; and `org-link-escape-browser' converts wrong to
- ;; [...]=%252Bsubject:%22Release+8.2%22.
- ;;
- ;; `url-encode-url' is available since Emacs 24.3.1 and
- ;; `org-link-escape-browser' can be removed altogether
- ;; once Org drops support for Emacs 24.1 and 24.2.
- (browse-url (funcall (if (fboundp 'url-encode-url)
- #'url-encode-url
- #'org-link-escape-browser)
- (concat type ":" path))))
+ (browse-url (org-link-escape-browser
+ (concat type ":" path))))
((string= type "doi")
- ;; See comments for type http above
- (browse-url (funcall (if (fboundp 'url-encode-url)
- #'url-encode-url
- #'org-link-escape-browser)
- (concat org-doi-server-url path))))
+ (browse-url (org-link-escape-browser
+ (concat org-doi-server-url path))))
((member type '("message"))
(browse-url (concat type ":" path)))
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 5ceea71..a8c924f 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2718,9 +2718,8 @@ INFO is a plist holding contextual information. See
(path
(cond
((member type '("http" "https" "ftp" "mailto"))
- (org-link-escape
- (org-link-unescape
- (concat type ":" raw-path)) org-link-escape-chars-browser))
+ (org-link-escape-browser
+ (org-link-unescape (concat type ":" raw-path))))
((string= type "file")
;; Treat links to ".org" files as ".html", if needed.
(setq raw-path
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 53c2409..0ca124c 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -655,12 +655,15 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
(org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
(ert-deftest test-org/org-link-escape-chars-browser ()
- "Escape a URL to pass to `browse-url'."
+ "Test of the constant `org-link-escape-chars-browser'.
+See there why this test is a candidate to be removed once Org
+drops support for Emacs 24.1 and 24.2."
(should
(string=
(concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
"%22Release%208.2%22&idxname=emacs-orgmode")
- (org-link-escape-browser
+ (org-link-escape-browser ; Do not replace with `url-encode-url',
+ ; see docstring above.
(concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
"\"Release 8.2\"&idxname=emacs-orgmode")))))