Browse Source

Fix "Fix `org-get-repeat'"

* lisp/org.el (org-get-repeat): Make sure matching group refers to the
  proper regexp.
* testing/lisp/test-org.el (test-org/get-repeat): New test.

The bug was introduced in aef7eef0f.
Nicolas Goaziou 8 years ago
parent
commit
737ada43c6
2 changed files with 23 additions and 1 deletions
  1. 1 1
      lisp/org.el
  2. 22 0
      testing/lisp/test-org.el

+ 1 - 1
lisp/org.el

@@ -13204,7 +13204,7 @@ on INACTIVE-OK."
 		      org-repeat-re)))
 	(catch :repeat
 	  (while (re-search-forward regexp end t)
-	    (when (org-at-timestamp-p)
+	    (when (save-match-data (org-at-timestamp-p))
 	      (throw :repeat (match-string-no-properties 1)))))))))
 
 (defvar org-last-changed-timestamp)

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

@@ -5595,6 +5595,28 @@ Paragraph<point>"
    (org-test-with-temp-text "<2012-03-29 Thu>"
      (org-timestamp-has-time-p (org-element-context)))))
 
+(ert-deftest test-org/get-repeat ()
+  "Test `org-get-repeat' specifications."
+  (should
+   (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
+     (org-get-repeat)))
+  (should-not
+   (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
+     (org-get-repeat)))
+  ;; Return proper repeat string.
+  (should
+   (equal "+2y"
+	  (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
+	    (org-get-repeat))))
+  ;; Prevent false positive (commented or verbatim time stamps)
+  (should-not
+   (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
+     (org-get-repeat)))
+  (should-not
+   (org-test-with-temp-text
+       "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
+     (org-get-repeat))))
+
 (ert-deftest test-org/timestamp-format ()
   "Test `org-timestamp-format' specifications."
   ;; Regular test.