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>
This commit is contained in:
Nicolas Goaziou 2016-10-24 23:56:34 +02:00
parent e5ca11cab8
commit dd670073de
2 changed files with 10 additions and 2 deletions

View File

@ -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"))))

View File

@ -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."