From d0018ce62c60379d19abf6d5010cf4281f1ec9d3 Mon Sep 17 00:00:00 2001 From: Bastien Date: Wed, 19 Feb 2020 10:55:36 +0100 Subject: [PATCH 1/2] ob-core.el: Fix `org-babel--string-to-number' * lisp/ob-core.el (org-babel--string-to-number): Prevent strings containing whitespaces after being trimmed to be interpreted as numbers. --- lisp/ob-core.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 7846474b6..9ab2fa920 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2932,9 +2932,10 @@ situations in which is it not appropriate." (defun org-babel--string-to-number (string) "If STRING represents a number return its value. Otherwise return nil." - (let ((interned-string (ignore-errors (read string)))) - (when (numberp interned-string) - interned-string))) + (unless (string-match-p "\\s-" (org-trim string)) + (let ((interned-string (ignore-errors (read string)))) + (when (numberp interned-string) + interned-string)))) (defun org-babel-import-elisp-from-file (file-name &optional separator) "Read the results located at FILE-NAME into an elisp table. From f90642e82838c7fea99781a0977fd6fa26aceee1 Mon Sep 17 00:00:00 2001 From: Bastien Date: Wed, 19 Feb 2020 10:56:10 +0100 Subject: [PATCH 2/2] test-ob.el: Fix and enhance tests * testing/lisp/test-ob.el (test-ob/string-to-number): Fix and enhance tests. --- testing/lisp/test-ob.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 681f3403e..97e1b49e7 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -2120,14 +2120,16 @@ abc (org-babel-execute-src-block)))))) (ert-deftest test-ob/string-to-number () - (should (= 0 (org-babel--string-to-number "0"))) - (should (= 1 (org-babel--string-to-number "1"))) - (should (eq nil (org-babel--string-to-number "000"))) - (should (eq nil (org-babel--string-to-number "001"))) - (should (eq nil (org-babel--string-to-number "010"))) - (should (= 100 (org-babel--string-to-number "100"))) - (should (= 0.1 (org-babel--string-to-number "0.1"))) - (should (= 1.0 (org-babel--string-to-number "1.0")))) + (should (= 0 (org-babel--string-to-number "0"))) + (should (= 1 (org-babel--string-to-number "1"))) + (should (eq nil (org-babel--string-to-number "1 2"))) + (should (= 1000.0 (org-babel--string-to-number "1e3"))) + (should (eq 0 (org-babel--string-to-number "000"))) + (should (eq 1 (org-babel--string-to-number "001"))) + (should (eq 10 (org-babel--string-to-number "010"))) + (should (= 100 (org-babel--string-to-number "100"))) + (should (= 0.1 (org-babel--string-to-number "0.1"))) + (should (= 1.0 (org-babel--string-to-number "1.0")))) (provide 'test-ob)