Yo~! fa5fd6351605912ec75e783cb626497b1ebe471e introduced a change where org-babel-script-escape stopped accepting numbers. This caused an issue in ob-ruby.el where when trying to evaluate something like "2 + 2", you would get the message:
`org-babel-script-escape' expects a string This broke evaluation of Ruby code blocks. I suspect this is not the only location where this problem might arise, so I am submitting a patch so the function simply returns numbers if they are passed in rather than dying. (Because numbers don't need to be escaped, and this was the previous behaviour.) Could you review my patch? Thanks..!
diff --git a/lisp/ob-core.el b/lisp/ob-core.el index e3abe97..01c4da8 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2813,34 +2813,37 @@ block but are passed literally to the \"example-block\"." (error "Unterminated string in `org-babel-script-escape'")) (apply #'string (reverse out)))) -(defun org-babel-script-escape (str &optional force) - "Safely convert tables into elisp lists." - (unless (stringp str) - (error "`org-babel-script-escape' expects a string")) - (let ((escaped - (cond - ((and (> (length str) 2) - (or (and (string-equal "[" (substring str 0 1)) - (string-equal "]" (substring str -1))) - (and (string-equal "{" (substring str 0 1)) - (string-equal "}" (substring str -1))) - (and (string-equal "(" (substring str 0 1)) - (string-equal ")" (substring str -1))))) - - (concat "'" (org-babel--script-escape-inner str))) - ((or force - (and (> (length str) 2) - (or (and (string-equal "'" (substring str 0 1)) - (string-equal "'" (substring str -1))) - ;; We need to pass double-quoted strings - ;; through the backslash-twiddling bits, even - ;; though we don't need to change their - ;; delimiters. - (and (string-equal "\"" (substring str 0 1)) - (string-equal "\"" (substring str -1)))))) - (org-babel--script-escape-inner str)) - (t str)))) - (condition-case nil (org-babel-read escaped) (error escaped)))) +(defun org-babel-script-escape (val &optional force) + "Safely convert passed in values (including collections of +them; tables) into elisp lists." + (if (numberp val) + val + (unless (stringp val) + (error "`org-babel-script-escape' expects a string or number")) + (let ((escaped + (cond + ((and (> (length val) 2) + (or (and (string-equal "[" (substring val 0 1)) + (string-equal "]" (substring val -1))) + (and (string-equal "{" (substring val 0 1)) + (string-equal "}" (substring val -1))) + (and (string-equal "(" (substring val 0 1)) + (string-equal ")" (substring val -1))))) + + (concat "'" (org-babel--script-escape-inner val))) + ((or force + (and (> (length val) 2) + (or (and (string-equal "'" (substring val 0 1)) + (string-equal "'" (substring val -1))) + ;; We need to pass double-quoted strings + ;; through the backslash-twiddling bits, even + ;; though we don't need to change their + ;; delimiters. + (and (string-equal "\"" (substring val 0 1)) + (string-equal "\"" (substring val -1)))))) + (org-babel--script-escape-inner val)) + (t val)))) + (condition-case nil (org-babel-read escaped) (error escaped))))) (defun org-babel-read (cell &optional inhibit-lisp-eval) "Convert the string value of CELL to a number if appropriate.