瀏覽代碼

org-element: Fix infloop when parsing a list at the end of buffer

* lisp/org-element.el (org-element-plain-list-parser): Fix infloop
  when parsing a list at the end of buffer, if buffer doesn't end at
  a line beginning.
* testing/lisp/test-org-element.el: Add test.
Nicolas Goaziou 11 年之前
父節點
當前提交
b4a8ec9321
共有 2 個文件被更改,包括 9 次插入6 次删除
  1. 1 2
      lisp/org-element.el
  2. 8 4
      testing/lisp/test-org-element.el

+ 1 - 2
lisp/org-element.el

@@ -1178,8 +1178,7 @@ Assume point is at the beginning of the list."
 		   (unless (bolp) (forward-line))
 		   (point)))
 	   (end (progn (skip-chars-forward " \r\t\n" limit)
-		       (skip-chars-backward " \t")
-		       (if (bolp) (point) (line-end-position)))))
+		       (if (= (point) limit) limit (line-beginning-position)))))
       ;; Return value.
       (list 'plain-list
 	    (nconc

+ 8 - 4
testing/lisp/test-org-element.el

@@ -1503,15 +1503,19 @@ e^{i\\pi}+1=0
   - inner
 
 Outside list"
-    (let ((endings (org-element-map
-		    (org-element-parse-buffer) 'plain-list
-		    (lambda (pl) (org-element-property :end pl)))))
+    (let ((endings (org-element-map (org-element-parse-buffer) 'plain-list
+		     (lambda (pl) (org-element-property :end pl)))))
       ;; Move to ending of outer list.
       (goto-char (car endings))
       (should (looking-at "Outside list"))
       ;; Move to ending of inner list.
       (goto-char (nth 1 endings))
-      (should (looking-at "^$")))))
+      (should (looking-at "^$"))))
+  ;; Correctly compute end of list if it doesn't end at a line
+  ;; beginning.
+  (should
+   (org-test-with-temp-text "- list\n   \n   "
+     (= (org-element-property :end (org-element-at-point)) (point-max)))))
 
 
 ;;;; Planning