diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 470db9fe6..a44d27cba 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -3346,6 +3346,26 @@ (defun org-babel-script-escape (str &optional force) (t str)))) (condition-case nil (org-babel-read escaped) (error escaped)))) +(defconst org-babel--quoted-string-regexp + (rx string-start + (zero-or-more (or space ?\n)) + ?\" + (group + (zero-or-more + ;; Anything besides double quotes ended not with backslash. + (zero-or-one (zero-or-more (not ?\")) + (not (or ?\" ?\\))) + ;; Skip backslashes escaping themselves. + (zero-or-more "\\\\") + ;; Escaped quotes are allowed. + (zero-or-one "\\\""))) + ?\" + (zero-or-more (or space ?\n)) + string-end) + "Regexp matching single string in double quotes. +Group 1 is text inside quotes. String may be optionally padded with +spaces. Backslashes quote other characters.") + (defun org-babel-read (cell &optional inhibit-lisp-eval) "Convert the string value of CELL to a number if appropriate. Otherwise if CELL looks like Lisp (meaning it starts with a @@ -3361,15 +3381,11 @@ (defun org-babel-read (cell &optional inhibit-lisp-eval) ;; FIXME: Arbitrary code evaluation. (eval (read cell) t)) ((save-match-data - (and (string-match "^[[:space:]]*\"\\(.*\\)\"[[:space:]]*$" cell) - ;; CELL is a single string - (with-temp-buffer - (insert cell) - (goto-char 1) - (read (current-buffer)) - (skip-chars-forward "[:space:]") - (eobp)))) - (read cell)) + (and (string-match org-babel--quoted-string-regexp cell) + ;; Unquote characters escaped by backslashes similar to `read'. + (replace-regexp-in-string + "\\\\\\(?:\\(.\\)\\|\n\\)" "\\1" + (match-string 1 cell) 'fixedcase nil)))) (t (org-no-properties cell)))) (defun org-babel--string-to-number (string)