mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-02-08 20:58:58 +00:00
Validate SPEC of `dolist', cf. Bug#25477.
* lisp/subr.el (dolist): Test type and length of SPEC. * test/lisp/subr-tests.el (subr-tests--dolist--wrong-number-of-args): Add unit test.
This commit is contained in:
parent
5ea696fd24
commit
98bfac68b9
@ -190,6 +190,10 @@ Then evaluate RESULT to get return value, default nil.
|
||||
|
||||
\(fn (VAR LIST [RESULT]) BODY...)"
|
||||
(declare (indent 1) (debug ((symbolp form &optional form) body)))
|
||||
(unless (consp spec)
|
||||
(signal 'wrong-type-argument (list 'consp spec)))
|
||||
(unless (<= 2 (length spec) 3)
|
||||
(signal 'wrong-number-of-arguments (list '(2 . 3) (length spec))))
|
||||
;; It would be cleaner to create an uninterned symbol,
|
||||
;; but that uses a lot more space when many functions in many files
|
||||
;; use dolist.
|
||||
|
@ -281,5 +281,15 @@ indirectly `mapbacktrace'."
|
||||
(should (equal (string-match-p "\\`[[:blank:]]\\'" "\u3000") 0))
|
||||
(should-not (string-match-p "\\`[[:blank:]]\\'" "\N{LINE SEPARATOR}")))
|
||||
|
||||
(ert-deftest subr-tests--dolist--wrong-number-of-args ()
|
||||
"Test that `dolist' doesn't accept wrong types or length of SPEC,
|
||||
cf. Bug#25477."
|
||||
(should-error (eval '(dolist (a)))
|
||||
:type 'wrong-number-of-arguments)
|
||||
(should-error (eval '(dolist (a () 'result 'invalid)) t)
|
||||
:type 'wrong-number-of-arguments)
|
||||
(should-error (eval '(dolist "foo") t)
|
||||
:type 'wrong-type-argument))
|
||||
|
||||
(provide 'subr-tests)
|
||||
;;; subr-tests.el ends here
|
||||
|
Loading…
x
Reference in New Issue
Block a user