summaryrefslogtreecommitdiff
path: root/test/lisp/emacs-lisp/bindat-tests.el
diff options
context:
space:
mode:
authorRichard Hansen <rhansen@rhansen.org>2022-06-12 01:19:43 -0400
committerEli Zaretskii <eliz@gnu.org>2022-06-12 09:59:13 +0300
commitc1829b307cffce046bec6fcbdff03dbab9f4b562 (patch)
tree0814466d82fb9bf840ba719a060f2026931fa643 /test/lisp/emacs-lisp/bindat-tests.el
parentc2695621fc52aa5eeebc45b82b9b916e30568589 (diff)
downloademacs-c1829b307cffce046bec6fcbdff03dbab9f4b562.tar.gz
emacs-c1829b307cffce046bec6fcbdff03dbab9f4b562.tar.bz2
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/lisp/emacs-lisp/bindat-tests.el')
-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 @@
(apply #'bindat-pack (append (car tc) (list prealloc)))
(should (equal prealloc (cdr tc))))))
+(ert-deftest bindat-test--str-strz-multibyte ()
+ (dolist (spec (list (bindat-type str 2)
+ (bindat-type strz 2)
+ (bindat-type strz)))
+ (should (equal (bindat-pack spec (string-to-multibyte "x")) "x\0"))
+ (should (equal (bindat-pack spec (string-to-multibyte "\xff")) "\xff\0"))
+ (should-error (bindat-pack spec "💩"))
+ (should-error (bindat-pack spec "\N{U+ff}")))
+ (dolist (spec (list '((x str 2)) '((x strz 2))))
+ (should (equal (bindat-pack spec `((x . ,(string-to-multibyte "x"))))
+ "x\0"))
+ (should (equal (bindat-pack spec `((x . ,(string-to-multibyte "\xff"))))
+ "\xff\0"))
+ (should-error (bindat-pack spec '((x . "💩"))))
+ (should-error (bindat-pack spec '((x . "\N{U+ff}"))))))
+
(let ((spec (bindat-type strz 2)))
(ert-deftest bindat-test--strz-fixedlen-len ()
(should (equal (bindat-length spec "") 2))