From 269b68090052fbc92c7a8bff96cbabd1bd736fb4 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 15 Mar 2015 12:07:40 +0100 Subject: [PATCH] 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. --- lisp/org.el | 15 +++------------ testing/lisp/test-org.el | 7 +++++++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index f6828f706..dcfea74c3 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -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 diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index f936e3db3..afe72aee2 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -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]]" + (goto-char (point-max)) + (let (org-link-search-must-match-exact-headline) (org-open-at-point)) (org-looking-at-p "\\* H1")))) ;;;; Fuzzy Links -- 2.11.4.GIT