From 0227e12605ef377698d38dc614f8697d382b973c Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Sat, 4 May 2024 22:19:45 +0300 Subject: [PATCH] org-babel-read: Read quotes strings ignoring leading/trailing newlines * lisp/ob-core.el (org-babel-read): When reading "string", ignore leading/trailing newlines in addition to spaces. * testing/lisp/test-ob.el (test-ob/org-babel-read): Add more tests. Reported-by: Max Nikulin Link: https://orgmode.org/list/v15lva$hhl$1@ciao.gmane.io --- lisp/ob-core.el | 4 ++-- testing/lisp/test-ob.el | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 082e9bd9e..3d975bec2 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -3363,9 +3363,9 @@ situations in which is it not appropriate." ((let (read-val) (save-match-data (and (string-match - (rx bos (0+ space) + (rx bos (0+ (any space ?\n)) ?\" (0+ anychar) ?\" - (0+ space) eos) + (0+ (any space ?\n)) eos) cell) ;; CELL is a single string (with-temp-buffer diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 30ce2875c..544e68267 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -2554,6 +2554,7 @@ abc (should (equal 1.2 (org-babel-read "1.2" inhibit))) ;; Allow whitespace (should (equal 1 (org-babel-read " 1 " inhibit))) + (should (equal 1 (org-babel-read " 1\n" inhibit))) ;; Not a number (should-not (equal 1 (org-babel-read "1foo" inhibit))) ;; Empty string @@ -2598,12 +2599,15 @@ abc (org-babel-read "*this*" inhibit)))) ;; Special case: data inside quotes (should (equal "foo" (org-babel-read " \"foo\" " inhibit))) + (should (equal "foo" (org-babel-read " \"foo\"\n" inhibit))) (should (equal "foo with\" inside" (org-babel-read " \"foo with\\\" inside\" " inhibit))) (should (equal "abc\nsdf" (org-babel-read "\"abc\nsdf\"" inhibit))) (should (equal "foo" (org-babel-read "\"foo\"" inhibit))) (should (equal "\"foo\"(\"bar\"" (org-babel-read "\"foo\"(\"bar\"" inhibit))) ;; Unpaired quotes - (should (equal "\"foo\"\"bar\"" (org-babel-read "\"foo\"\"bar\"" inhibit))))) + (should (equal "\"foo\"\"bar\"" (org-babel-read "\"foo\"\"bar\"" inhibit))) + ;; Recover from `read' parsing errors. + (org-babel-read "\"Quoted closing quote:\\\"" inhibit))) (ert-deftest test-ob/demarcate-block-split-duplication () "Test duplication of language, body, switches, and headers in splitting."