branch: externals/org
commit 5af062511336cb586e846303e8f79a6aa64da3d5
Author: Ihor Radchenko <yanta...@posteo.net>
Commit: Ihor Radchenko <yanta...@posteo.net>

    org-table-eval-formula: Fix parsing of mode string when formula has ;
    
    * lisp/org-table.el (org-table-eval-formula): Use more strict regexp
    to detect mode string in formulas.
    * testing/lisp/test-org-table.el (test-org-table/eval-formula): Add
    test.
    
    Reported-by: Nick Dokos <ndo...@gmail.com>
    Link: https://orgmode.org/list/87ply5v1gj.fsf@localhost
---
 lisp/org-table.el              | 8 +++++++-
 testing/lisp/test-org-table.el | 6 ++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 0dbe6b0225..56c5a4aac2 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -2491,7 +2491,13 @@ location of point."
           duration duration-output-format)
       ;; Parse the format string.  Since we have a lot of modes, this is
       ;; a lot of work.  However, I think calc still uses most of the time.
-      (if (string-match "\\(.*\\);\\(.*\\)" formula)
+      (if (string-match
+           (rx (group (0+ any)) ";"
+               (group
+                (1+ (or whitespace
+                        (seq (in "pnfse") (opt "-") (1+ digit))
+                        (in "tTUNLEDRFSu")))))
+           formula)
          (progn
            (setq fmt (concat (cdr (assoc "%" org-table-local-parameters))
                              (match-string-no-properties 2 formula)))
diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el
index df63a65fc8..0a29ba3626 100644
--- a/testing/lisp/test-org-table.el
+++ b/testing/lisp/test-org-table.el
@@ -2026,6 +2026,12 @@ See also `test-org-table/copy-field'."
    (equal "| 1 | 1 |"
          (org-test-with-temp-text "| 1 | <point>  |"
            (org-table-eval-formula nil "$<" nil nil t)
+           (buffer-string))))
+  ;; Do not disambiguate ; in the formula itself with mode string.
+  (should
+   (equal "| 1 | 1; |"
+         (org-test-with-temp-text "| 1 | <point>  |"
+           (org-table-eval-formula nil "'(concat $1 \";\")" nil nil t)
            (buffer-string)))))
 
 (ert-deftest test-org-table/field-formula-outside-table ()

Reply via email to