Browse Source

Fix opening custom ID links with percent escaped syntax

* lisp/org.el (org-open-at-point): Un-escape percent escaped path.
* testing/lisp/test-org.el (test-org/custom-id): Add test.

Reported-by: stardiviner <numbchild@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2018-11/msg00303.html>
Nicolas Goaziou 6 months ago
parent
commit
cd60a35fe1
2 changed files with 10 additions and 3 deletions
  1. 4 3
      lisp/org.el
  2. 6 0
      testing/lisp/test-org.el

+ 4 - 3
lisp/org.el

@@ -10284,9 +10284,10 @@ a link."
 			    (org-search-radio-target
 			     (org-element-property :path context))
 			  (org-link-search
-			   (if (member type '("custom-id" "coderef"))
-			       (org-element-property :raw-link context)
-			     path)
+			   (pcase type
+			     ("custom-id" (concat "#" path))
+			     ("coderef" (format "(%s)" path))
+			     (_ path))
 			   ;; Prevent fuzzy links from matching
 			   ;; themselves.
 			   (and (equal type "fuzzy")

+ 6 - 0
testing/lisp/test-org.el

@@ -2338,6 +2338,12 @@ SCHEDULED: <2014-03-04 tue.>"
        "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
      (org-open-at-point)
      (looking-at-p "\\* H1")))
+  ;; Handle escape characters.
+  (should
+   (org-test-with-temp-text
+       "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#%5B%25%5D<point>]]"
+     (org-open-at-point)
+     (looking-at-p "\\* H1")))
   ;; Throw an error on false positives.
   (should-error
    (org-test-with-temp-text