dovecot-2.2: lib: test-unichar - test invalid utf8 encodings

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 1 19:18:47 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/3468de815591
changeset: 18784:3468de815591
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jun 01 22:07:44 2015 +0300
description:
lib: test-unichar - test invalid utf8 encodings
Chop trailing characters off valid encodings, and watch them fail.
(There's no need to do this on most of the test characters, as they're
truncated to the same byte sequence - only do 1 in 64.)

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib/test-unichar.c |  17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diffs (27 lines):

diff -r aa2f464daa66 -r 3468de815591 src/lib/test-unichar.c
--- a/src/lib/test-unichar.c	Mon Jun 01 22:06:44 2015 +0300
+++ b/src/lib/test-unichar.c	Mon Jun 01 22:07:44 2015 +0300
@@ -60,6 +60,23 @@
 		test_assert(uni_utf8_str_is_valid(str_c(str)));
 		test_assert(uni_utf8_get_char(str_c(str), &chr2) > 0);
 		test_assert(chr2 == chr);
+
+		if ((chr & 0x63) == 0) {
+			unsigned int utf8len = uni_utf8_char_bytes(*str_c(str));
+
+			/* virtually truncate the byte string */
+			while (--utf8len > 0)
+				test_assert(uni_utf8_get_char_n(str_c(str), utf8len, &chr2) == 0);
+
+			utf8len = uni_utf8_char_bytes(*str_c(str));
+
+			/* actually truncate the byte stream */
+			while (--utf8len > 0) {
+				str_truncate(str, utf8len);
+				test_assert(!uni_utf8_str_is_valid(str_c(str)));
+				test_assert(uni_utf8_get_char(str_c(str), &chr2) == 0);
+			}
+		}
 	}
 	test_end();
 


More information about the dovecot-cvs mailing list