Okay, and now I've patched the related string splitting functions so that
        ("let's get \"ready to rumble\" now")
is split into:
        ("let's" "get" "ready to rumble" "now")

All my tests are passing but a few unrelated ones are failing so I'll need
 to dig more into what's going on there. Attached is the 3rd patch

Best
From 3f39671f3ec55e6db076f2b1b5ccad12380eb32a Mon Sep 17 00:00:00 2001
From: Mehmet Tekman <mtekma...@gmail.com>
Date: Thu, 3 Aug 2023 08:22:03 +0200
Subject: [PATCH 3/3] * lisp/ob-core.el (org-babel-merge-params):
 (org-babel--split-str-quoted): Added quotes-aware string split function
 (org-babel-read): patched to add quotes to words with spaces

---
 lisp/ob-core.el | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 48337406a..0c36bcf00 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2919,6 +2919,21 @@ in EXCLUSIVE-GROUPS while merging lists in RESULT-PARAMS."
             (setq group-alist (append unexplained-params group-alist)))
         group-alist))))
 
+(defun org-babel--split-str-quoted (str)
+  "Splits a string that may or may not contain quotes"
+  (let (result pos)
+    (while (string-match (rx (or (seq "\"" (group (* (not "\""))) "\"")
+                                 (group (+ (not space)))))
+                         str pos)
+      (let ((match-str1 (match-string 1 str))
+            (match-str2 (match-string 2 str)))
+        (if match-str1
+            (progn
+              (push match-str1 result)
+              (setq pos (1+ (match-end 1))))
+          (push match-str2 result)
+          (setq pos (match-end 2)))))
+    (nreverse result)))
 
 (defun org-babel-merge-params (&rest plists)
   "Combine all parameter association lists in PLISTS.
@@ -2994,7 +3009,7 @@ parameters when merging lists."
            (setq tangle (org-babel--merge-headers
                          tangle-exclusive-groups
                          tangle
-                         (split-string
+                         (org-babel--split-str-quoted
                           (or value "")))))
           ((or '(:dir . attach) '(:dir . "'attach"))
            (unless (org-attach-dir nil t)
@@ -3319,9 +3334,14 @@ situations in which is it not appropriate."
          ;; FIXME: Arbitrary code evaluation.
 	 (eval (read cell) t))
 	((save-match-data
-           (and (string-match "^[[:space:]]*\"\\(.*\\)\"[[:space:]]*$" cell)
-                (not (string-match "[^\\]\"" (match-string 1 cell)))))
-         (read cell))
+           (and (string-match (rx bol (* space) "\"" (group (* any)) "\"" (* space) eol)
+                              cell)
+                (not (string-match (rx (not "\\") "\"") (match-string 1 cell)))))
+         (let ((res (read cell)))
+           ;; If the matched string contains spaces, surround it in quotes.
+           (if (string-match (rx (+ space)) res)
+               (concat "\"" res "\"")
+             res)))
 	(t (org-no-properties cell))))
 
 (defun org-babel--string-to-number (string)
-- 
2.41.0

Reply via email to