org-element: Fix infloop at the end of an incomplete table row

* lisp/org-element.el (org-element-context): Fix infloop.  Be more
  cautious when point is at the end of buffer.

* testing/lisp/test-org-element.el (test-org-element/context): Add
  test.
This commit is contained in:
Nicolas Goaziou 2014-04-17 21:37:07 +02:00
parent dd8b3cbf36
commit 2b2b2c5c99
2 changed files with 14 additions and 3 deletions

View File

@ -5745,8 +5745,11 @@ Providing it allows for quicker computation."
(cbeg (org-element-property :contents-begin next)) (cbeg (org-element-property :contents-begin next))
(cend (org-element-property :contents-end next))) (cend (org-element-property :contents-end next)))
(cond (cond
;; Skip objects ending before or at POS. ;; Skip objects ending before point. Also skip
((<= end pos) ;; objects ending at point unless it is also the
;; end of buffer, since we want to return the
;; innermost object.
((and (<= end pos) (/= (point-max) end))
(goto-char end) (goto-char end)
;; For convenience, when object ends at POS, ;; For convenience, when object ends at POS,
;; without any space, store it in LAST, as we ;; without any space, store it in LAST, as we
@ -5764,7 +5767,9 @@ Providing it allows for quicker computation."
;; object, for consistency with ;; object, for consistency with
;; convenience feature above. ;; convenience feature above.
(and (= pos cend) (and (= pos cend)
(not (memq (char-before pos) '(?\s ?\t)))))) (or (= (point-max) pos)
(not (memq (char-before pos)
'(?\s ?\t)))))))
(goto-char cbeg) (goto-char cbeg)
(narrow-to-region (point) cend) (narrow-to-region (point) cend)
(setq parent next (setq parent next

View File

@ -3076,6 +3076,12 @@ Paragraph \\alpha."
(eq 'bold (eq 'bold
(org-test-with-temp-text "* *bold*" (org-test-with-temp-text "* *bold*"
(search-forward "bo") (search-forward "bo")
(org-element-type (org-element-context)))))
;; Special case: incomplete cell at the end of a table row.
(should
(eq 'table-cell
(org-test-with-temp-text "|a|b|c"
(goto-char (point-max))
(org-element-type (org-element-context)))))) (org-element-type (org-element-context))))))