1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

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.
This commit is contained in:
Mauro Aranda 2023-09-09 21:59:30 +08:00 committed by Eli Zaretskii
parent 68976b00f1
commit 2ea98ea35c
2 changed files with 14 additions and 1 deletions

View file

@ -3681,7 +3681,9 @@ match-alternatives: %S"
:warning)
;; Make sure we will `read' a string.
(setq value (prin1-to-string value)))
(read value)))
(if (string-empty-p value)
value
(read value))))
(defun widget-restricted-sexp-match (widget value)
(let ((alternatives (widget-get widget :match-alternatives))

View file

@ -380,4 +380,15 @@ return nil, even with a non-nil bubblep argument."
:value (("1" . 1) ("2" . 2))))))
(should (equal '(("1" . 1) ("2" . 2)) (widget-default-get w))))))
(ert-deftest widget-test-restricted-sexp-empty-val ()
"Test that we handle an empty restricted-sexp widget just fine."
(with-temp-buffer
(let ((w (widget-create '(restricted-sexp
:value 3
:match-alternatives (integerp)))))
(widget-setup)
(widget-backward 1)
(delete-char 1)
(should (string= (widget-value w) "")))))
;;; wid-edit-tests.el ends here