summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-10-24 23:56:34 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-10-24 23:56:34 +0200
commitdd670073de1a54f1146619cdbac2b0141f6d19af (patch)
tree8e675bfe04b7fcb2f30f98fdc99b8d3322fcb2ca
parente5ca11cab882838b3afea7abf3794376437505ee (diff)
downloadorg-mode-dd670073de1a54f1146619cdbac2b0141f6d19af.tar.gz
org-element: Fix interpreting links with % in description
* lisp/org-element.el (org-element-link-interpreter): % in description are confused with format string placeholders. Escape them so as to fix the error. * testing/lisp/test-org-element.el (test-org-element/link-interpreter): Add test. Reported-by: Daniel Clemente <n142857@gmail.com> <http://permalink.gmane.org/gmane.emacs.orgmode/109878>
-rw-r--r--lisp/org-element.el7
-rw-r--r--testing/lisp/test-org-element.el5
2 files changed, 10 insertions, 2 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 5ebce6c..cbd842f 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -3194,7 +3194,12 @@ CONTENTS is the contents of the object, or nil."
;; cases. This is also the default syntax when the
;; property is not defined, e.g., when the object
;; was crafted by the user.
- ((guard contents) (format "[[%%s][%s]]" contents))
+ ((guard contents)
+ (format "[[%%s][%s]]"
+ ;; Since this is going to be used as
+ ;; a format string, escape percent signs
+ ;; in description.
+ (replace-regexp-in-string "%" "%%" contents)))
((or `bracket
`nil
(guard (member type '("coderef" "custom-id" "fuzzy"))))
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index ae78e73..35cd28b 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -3026,7 +3026,10 @@ DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu
"http://orgmode.org\n"))
;; Angular links.
(should (equal (org-test-parse-and-interpret "<http://orgmode.org>")
- "<http://orgmode.org>\n")))
+ "<http://orgmode.org>\n"))
+ ;; Pathological case: link with a %-sign in description.
+ (should (equal (org-test-parse-and-interpret "[[file://path][%s]]")
+ "[[file://path][%s]]\n")))
(ert-deftest test-org-element/macro-interpreter ()
"Test macro interpreter."