diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-23 19:51:51 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-23 19:51:51 -0500 |
| commit | beb6558a7a7a95e54d7cc510e4832bf645950e51 (patch) | |
| tree | a0c44e53eeda304feb78487db3f5350d4cb9956b /tests | |
| parent | c90e8deaef6fe29bce4dab778630e3ba5f1c7956 (diff) | |
| download | dotemacs-beb6558a7a7a95e54d7cc510e4832bf645950e51.tar.gz dotemacs-beb6558a7a7a95e54d7cc510e4832bf645950e51.zip | |
fix(org-babel): confirm babel evaluation by default, toggle on a key
org-babel-config set org-confirm-babel-evaluate to nil globally, so a source block in any Org file (a cloned repo, a downloaded note, a web clip) ran with no prompt. That's arbitrary code execution on opening the wrong file and hitting C-c C-c.
I set the default to t (confirm) and replaced the old babel-confirm command, which only toggled under a prefix arg, with cj/org-babel-toggle-confirm. It flips confirmation off for the session when I'm in trusted files and back on when I'm done, bound to C-; k.
The C-; k binding is a placeholder. I filed a follow-up to give it a permanent Org-prefixed home.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-org-babel-config.el | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test-org-babel-config.el b/tests/test-org-babel-config.el new file mode 100644 index 00000000..b62a9422 --- /dev/null +++ b/tests/test-org-babel-config.el @@ -0,0 +1,35 @@ +;;; test-org-babel-config.el --- Tests for babel confirmation toggle -*- lexical-binding: t; -*- + +;;; Commentary: +;; Covers cj/org-babel-toggle-confirm, which flips `org-confirm-babel-evaluate' +;; between t (the safe default — confirm before running a block) and nil, and +;; the C-; k binding that invokes it. + +;;; Code: + +(require 'ert) +(require 'org-babel-config) + +;; org defines this as a defcustom, but org is not loaded in batch; declare it +;; special here so the let-bindings below are dynamic. +(defvar org-confirm-babel-evaluate t) + +(ert-deftest test-org-babel-toggle-confirm-flips-from-t-to-nil () + "Normal: toggling when confirmation is on turns it off." + (let ((org-confirm-babel-evaluate t)) + (cj/org-babel-toggle-confirm) + (should-not org-confirm-babel-evaluate))) + +(ert-deftest test-org-babel-toggle-confirm-flips-from-nil-to-t () + "Normal: toggling when confirmation is off turns it on." + (let ((org-confirm-babel-evaluate nil)) + (cj/org-babel-toggle-confirm) + (should (eq t org-confirm-babel-evaluate)))) + +(ert-deftest test-org-babel-toggle-confirm-bound-to-key () + "Smoke: C-; k invokes the toggle command." + (should (eq (keymap-lookup (current-global-map) "C-; k") + #'cj/org-babel-toggle-confirm))) + +(provide 'test-org-babel-config) +;;; test-org-babel-config.el ends here |
