aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Aranda2023-09-09 21:59:30 +0800
committerEli Zaretskii2023-09-16 12:56:34 +0300
commit2ea98ea35c82da31ef419da3b49789ab750e8e00 (patch)
treeeb0329873307c052873b331105ec094c114e4246
parent68976b00f1024f4bd3b5f2f91c090426c03f609a (diff)
downloademacs-2ea98ea35c82da31ef419da3b49789ab750e8e00.tar.gz
emacs-2ea98ea35c82da31ef419da3b49789ab750e8e00.zip
Avoid errors when a restricted-sexp widget is empty
* lisp/wid-edit.el (restricted-sexp): Don't try to read an empty string when converting the current value to the external format. (Bug#63838) * test/lisp/wid-edit-tests.el (widget-test-restricted-sexp-empty-val): New test.
-rw-r--r--lisp/wid-edit.el4
-rw-r--r--test/lisp/wid-edit-tests.el11
2 files changed, 14 insertions, 1 deletions
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index d18d721f7ed..74412414113 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -3681,7 +3681,9 @@ match-alternatives: %S"
3681 :warning) 3681 :warning)
3682 ;; Make sure we will `read' a string. 3682 ;; Make sure we will `read' a string.
3683 (setq value (prin1-to-string value))) 3683 (setq value (prin1-to-string value)))
3684 (read value))) 3684 (if (string-empty-p value)
3685 value
3686 (read value))))
3685 3687
3686(defun widget-restricted-sexp-match (widget value) 3688(defun widget-restricted-sexp-match (widget value)
3687 (let ((alternatives (widget-get widget :match-alternatives)) 3689 (let ((alternatives (widget-get widget :match-alternatives))
diff --git a/test/lisp/wid-edit-tests.el b/test/lisp/wid-edit-tests.el
index ebfe729bc9a..66bff4ad2e3 100644
--- a/test/lisp/wid-edit-tests.el
+++ b/test/lisp/wid-edit-tests.el
@@ -380,4 +380,15 @@ return nil, even with a non-nil bubblep argument."
380 :value (("1" . 1) ("2" . 2)))))) 380 :value (("1" . 1) ("2" . 2))))))
381 (should (equal '(("1" . 1) ("2" . 2)) (widget-default-get w)))))) 381 (should (equal '(("1" . 1) ("2" . 2)) (widget-default-get w))))))
382 382
383(ert-deftest widget-test-restricted-sexp-empty-val ()
384 "Test that we handle an empty restricted-sexp widget just fine."
385 (with-temp-buffer
386 (let ((w (widget-create '(restricted-sexp
387 :value 3
388 :match-alternatives (integerp)))))
389 (widget-setup)
390 (widget-backward 1)
391 (delete-char 1)
392 (should (string= (widget-value w) "")))))
393
383;;; wid-edit-tests.el ends here 394;;; wid-edit-tests.el ends here