ob-core: Fix regression

* lisp/ob-core.el (org-babel-balanced-split): Fix regression
  introduced in 500abcd7fb.

* testing/lisp/test-ob.el (test-ob/balanced-split): Add tests.

Reported-by: Eric S Fraga <e.fraga@ucl.ac.uk>
<http://permalink.gmane.org/gmane.emacs.orgmode/113401>
This commit is contained in:
Nicolas Goaziou 2017-05-08 11:25:17 +02:00
parent a4f29410e9
commit f1da21f7d9
2 changed files with 17 additions and 11 deletions

View File

@ -1487,19 +1487,17 @@ balanced instances of \"[ \t]:\", set ALTS to ((32 9) . 58)."
(push after partial)
(goto-char (1+ origin)))))
((and (eq ?\" (char-after)) (not (eq ?\\ (char-before))))
;; Include everything between non-escaped double quotes.
(push ?\" partial)
;; Include everything from current double quote to next
;; non-escaped double quote.
(let ((origin (point)))
(condition-case nil
;; Use `read' since it is fast and takes care of
;; escaped quotes already.
(if (re-search-forward "[^\\]\"" nil t)
(setq partial
(nconc (cons ?\"
(nreverse (string-to-list
(read (current-buffer)))))
(nconc (nreverse (string-to-list
(buffer-substring origin (point))))
partial))
;; No closing double quote found. Backtrack.
(end-of-file (goto-char (1+ origin))))))
;; No closing double quote. Backtrack.
(push ?\" partial)
(forward-char))))
(t (push (char-after) partial)
(forward-char))))
;; Add pending parsing and return result.

View File

@ -717,7 +717,15 @@ x
;; Handle un-balanced quotes.
(should
(equal '(":foo \"1" "bar 3")
(org-babel-balanced-split ":foo \"1 :bar 3" '((32 9) . 58)))))
(org-babel-balanced-split ":foo \"1 :bar 3" '((32 9) . 58))))
;; Handle empty string.
(should
(equal '(":foo \"\"")
(org-babel-balanced-split ":foo \"\"" '((32 9) . 58))))
;; Handle control characters within double quotes.
(should
(equal '(":foo \"\\n\"")
(org-babel-balanced-split ":foo \"\\n\"" '((32 9) . 58)))))
(ert-deftest test-ob/commented-last-block-line-no-var ()
(org-test-with-temp-text-in-file "