From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vladimir Panteleev Subject: [PATCH v2 1/3] ob-table: Fix org-sbe's handling of quotes in cell values Date: Mon, 19 Mar 2018 00:23:12 +0000 Message-ID: <20180319002314.8162-2-git@thecybershadow.net> References: <20180319002314.8162-1-git@thecybershadow.net> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exiaK-0002jb-BB for emacs-orgmode@gnu.org; Sun, 18 Mar 2018 20:23:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1exiaG-0000Xq-Bn for emacs-orgmode@gnu.org; Sun, 18 Mar 2018 20:23:32 -0400 Received: from mail-wr0-f174.google.com ([209.85.128.174]:34072) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1exiaG-0000Wr-58 for emacs-orgmode@gnu.org; Sun, 18 Mar 2018 20:23:28 -0400 Received: by mail-wr0-f174.google.com with SMTP id o8so16910412wra.1 for ; Sun, 18 Mar 2018 17:23:28 -0700 (PDT) In-Reply-To: <20180319002314.8162-1-git@thecybershadow.net> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Cc: Vladimir Panteleev * ob-table.el (org-sbe): org-sbe did the wrong thing when given a reference to a cell containing quotes or backslashes, because it would simply wrap any $-prefixed value in quotes, without any escaping. Fix this by using "%S" (instead of "\"%s\""). * test-ob-table.el: Add test. --- lisp/ob-table.el | 2 +- testing/lisp/test-ob-table.el | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lisp/ob-table.el b/lisp/ob-table.el index f6a5c88e4..105aca5e2 100644 --- a/lisp/ob-table.el +++ b/lisp/ob-table.el @@ -112,7 +112,7 @@ as shown in the example below. (prog1 nil (setq quote t)) (prog1 (cond - (quote (format "\"%s\"" el)) + (quote (format "%S" el)) ((stringp el) (org-no-properties el)) (t el)) (setq quote nil)))) diff --git a/testing/lisp/test-ob-table.el b/testing/lisp/test-ob-table.el index da136cbee..3d9b1d160 100644 --- a/testing/lisp/test-ob-table.el +++ b/testing/lisp/test-ob-table.el @@ -30,6 +30,28 @@ ;; (org-test-at-id "6d2ff4ce-4489-4e2a-9c65-e3f71f77d975" ;; (should (= 2 (sbe take-sqrt (n "4")))))) +(ert-deftest test-ob-table/sbe-quote () + "Test that `org-sbe' can correctly handle cell values containing quotes." + (org-test-table-target-expect + " +#+name: identity +#+begin_src emacs-lisp :eval yes + x +#+end_src + +| a\"b\"c | replace | +" + " +#+name: identity +#+begin_src emacs-lisp :eval yes + x +#+end_src + +| a\"b\"c | a\"b\"c | +" + 1 + "#+TBLFM: $2 = '(org-sbe identity (x $$1))")) + (provide 'test-ob-table) ;;; test-ob-table.el ends here -- 2.16.2