Fix CUSTOM_ID search

* lisp/org.el (org-link-search): Avoid false positives when searching
  CUSTOM_ID property.

* testing/lisp/test-org.el (test-org/custom-id): Add test.
This commit is contained in:
Nicolas Goaziou 2015-03-15 12:07:40 +01:00
parent 7072dba04d
commit 269b680900
2 changed files with 10 additions and 12 deletions

View File

@ -10999,19 +10999,10 @@ variable."
;; First check if there are any special search functions
((run-hook-with-args-until-success 'org-execute-file-search-functions s))
;; Now try the builtin stuff
((and (equal (string-to-char s0) ?#)
((and (eq (aref s0 0) ?#)
(> (length s0) 1)
(save-excursion
(goto-char (point-min))
(and
(re-search-forward
(concat "^[ \t]*:CUSTOM_ID:[ \t]+"
(regexp-quote (substring s0 1)) "[ \t]*$") nil t)
(setq type 'dedicated
pos (match-beginning 0))))
;; There is an exact target for this
(goto-char pos)
(org-back-to-heading t)))
(let ((match (org-find-property "CUSTOM_ID" (substring s0 1))))
(and match (goto-char match) (setf type 'dedicated)))))
((save-excursion
(goto-char (point-min))
(and

View File

@ -1313,6 +1313,13 @@
"* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
(goto-char (point-max))
(org-open-at-point)
(org-looking-at-p "\\* H1")))
;; Ignore false positives.
(should-not
(org-test-with-temp-text
"* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]<point>"
(goto-char (point-max))
(let (org-link-search-must-match-exact-headline) (org-open-at-point))
(org-looking-at-p "\\* H1"))))
;;;; Fuzzy Links