[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 98bfac6: Validate SPEC of `dolist', cf. Bug#25477.
From: |
Philipp Stephani |
Subject: |
[Emacs-diffs] master 98bfac6: Validate SPEC of `dolist', cf. Bug#25477. |
Date: |
Sat, 8 Apr 2017 11:36:22 -0400 (EDT) |
branch: master
commit 98bfac68b98e051425c41873edc48f9af5c92361
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>
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.
---
lisp/subr.el | 4 ++++
test/lisp/subr-tests.el | 10 ++++++++++
2 files changed, 14 insertions(+)
diff --git a/lisp/subr.el b/lisp/subr.el
index 13567d8..1dd5d2f 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -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.
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index a3b08e9..0d243cc 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 98bfac6: Validate SPEC of `dolist', cf. Bug#25477.,
Philipp Stephani <=