Browse Source

`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 <joesmoe10@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/108559>
Nicolas Goaziou 8 years ago
parent
commit
406ad6eb52
2 changed files with 9 additions and 2 deletions
  1. 3 1
      lisp/org.el
  2. 6 1
      testing/lisp/test-org.el

+ 3 - 1
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
 			    "\\(.*?\\)"

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

@@ -1438,7 +1438,12 @@
   (should
    (equal "Todo H"
 	  (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
-	    (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."