From 406ad6eb52f843441f45abd9699bc6f5bc473ab2 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 30 Jul 2016 22:30:19 +0200 Subject: [PATCH] `org-get-heading' is more consistent on empty headlines * lisp/org.el (org-get-heading): Ensure that return value is always a string. * testing/lisp/test-org.el (test-org/get-heading): Add tests. Reported-by: Joe Schafer --- lisp/org.el | 4 +++- testing/lisp/test-org.el | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index e183053fe..05432bbf5 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -8092,7 +8092,9 @@ When NO-TODO is non-nil, don't include TODO keywords." (cond ((and no-tags no-todo) (looking-at org-complex-heading-regexp) - (match-string 4)) + ;; Return value has to be a string, but match group 4 is + ;; optional. + (or (match-string 4) "")) (no-tags (looking-at (concat org-outline-regexp "\\(.*?\\)" diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index b57d0acc4..5d0edf4e1 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1438,7 +1438,12 @@ (should (equal "Todo H" (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H" - (org-get-heading nil t))))) + (org-get-heading nil t)))) + ;; On an empty headline, return value is consistent. + (should (equal "" (org-test-with-temp-text "* " (org-get-heading)))) + (should (equal "" (org-test-with-temp-text "* " (org-get-heading t)))) + (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t)))) + (should (equal "" (org-test-with-temp-text "* " (org-get-heading t t))))) (ert-deftest test-org/in-commented-heading-p () "Test `org-in-commented-heading-p' specifications."