From f1da21f7d911e412cc6846acd66dd3d2056553d5 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 8 May 2017 11:25:17 +0200 Subject: [PATCH] ob-core: Fix regression * lisp/ob-core.el (org-babel-balanced-split): Fix regression introduced in 500abcd7fbe24abc887300faec2058905a13fa33. * testing/lisp/test-ob.el (test-ob/balanced-split): Add tests. Reported-by: Eric S Fraga --- lisp/ob-core.el | 18 ++++++++---------- testing/lisp/test-ob.el | 10 +++++++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 8a4c1ba64..c630b70f9 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -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. diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index fe4ecb85e..a1bdc54b7 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -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 "