aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRichard Hansen2022-06-12 01:19:43 -0400
committerEli Zaretskii2022-06-12 09:59:13 +0300
commitc1829b307cffce046bec6fcbdff03dbab9f4b562 (patch)
tree0814466d82fb9bf840ba719a060f2026931fa643 /test
parentc2695621fc52aa5eeebc45b82b9b916e30568589 (diff)
downloademacs-c1829b307cffce046bec6fcbdff03dbab9f4b562.tar.gz
emacs-c1829b307cffce046bec6fcbdff03dbab9f4b562.zip
bindat (str, strz): Reject non-ASCII, non-`eight-bit' characters
* lisp/emacs-lisp/bindat.el (str) (strz): Signal an error if the user attempts to pack a multibyte string containing characters other than ASCII and `eight-bit' characters (bug#55897). * doc/lispref/processes.texi (Bindat Types): Update documentation. * test/lisp/emacs-lisp/bindat-tests.el (str) (strz): Add tests.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/bindat-tests.el16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/bindat-tests.el b/test/lisp/emacs-lisp/bindat-tests.el
index 1ce402977f5..8bb3baa485e 100644
--- a/test/lisp/emacs-lisp/bindat-tests.el
+++ b/test/lisp/emacs-lisp/bindat-tests.el
@@ -188,6 +188,22 @@
188 (apply #'bindat-pack (append (car tc) (list prealloc))) 188 (apply #'bindat-pack (append (car tc) (list prealloc)))
189 (should (equal prealloc (cdr tc)))))) 189 (should (equal prealloc (cdr tc))))))
190 190
191(ert-deftest bindat-test--str-strz-multibyte ()
192 (dolist (spec (list (bindat-type str 2)
193 (bindat-type strz 2)
194 (bindat-type strz)))
195 (should (equal (bindat-pack spec (string-to-multibyte "x")) "x\0"))
196 (should (equal (bindat-pack spec (string-to-multibyte "\xff")) "\xff\0"))
197 (should-error (bindat-pack spec "💩"))
198 (should-error (bindat-pack spec "\N{U+ff}")))
199 (dolist (spec (list '((x str 2)) '((x strz 2))))
200 (should (equal (bindat-pack spec `((x . ,(string-to-multibyte "x"))))
201 "x\0"))
202 (should (equal (bindat-pack spec `((x . ,(string-to-multibyte "\xff"))))
203 "\xff\0"))
204 (should-error (bindat-pack spec '((x . "💩"))))
205 (should-error (bindat-pack spec '((x . "\N{U+ff}"))))))
206
191(let ((spec (bindat-type strz 2))) 207(let ((spec (bindat-type strz 2)))
192 (ert-deftest bindat-test--strz-fixedlen-len () 208 (ert-deftest bindat-test--strz-fixedlen-len ()
193 (should (equal (bindat-length spec "") 2)) 209 (should (equal (bindat-length spec "") 2))