Преглед на файлове

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 <e.fraga@ucl.ac.uk>
<http://permalink.gmane.org/gmane.emacs.orgmode/113401>
Nicolas Goaziou преди 7 години
родител
ревизия
f1da21f7d9
променени са 2 файла, в които са добавени 17 реда и са изтрити 11 реда
  1. 8 10
      lisp/ob-core.el
  2. 9 1
      testing/lisp/test-ob.el

+ 8 - 10
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.

+ 9 - 1
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 "