From 0f950f4b9d2f89fe397138f336203270b96e06c9 Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Fri, 9 Jun 2017 15:16:25 +0100 Subject: [PATCH] Check that ASCII-like encoding is valid --- expat/tests/runtests.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index db454664..33c6df3a 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -5483,6 +5483,35 @@ START_TEST(test_invalid_unknown_encoding) } END_TEST +static int XMLCALL +AsciiAsUnknownEncodingHandler(void *UNUSED_P(data), + const XML_Char *UNUSED_P(encoding), + XML_Encoding *info) +{ + int i; + + for (i = 0; i < 128; i++) + info->map[i] = i; + for (; i < 256; i++) + info->map[i] = -1; /* Invalid characters */ + info->data = NULL; + info->convert = NULL; + info->release = NULL; + return XML_STATUS_OK; +} + +START_TEST(test_unknown_ascii_encoding_ok) +{ + const char *text = + "\n" + "Hello, world"; + + XML_SetUnknownEncodingHandler(parser, AsciiAsUnknownEncodingHandler, NULL); + run_character_check(text, "Hello, world"); +} +END_TEST + + /* * Namespaces tests. */ @@ -10747,6 +10776,7 @@ make_suite(void) tcase_add_test(tc_basic, test_unknown_encoding_long_name_1); tcase_add_test(tc_basic, test_unknown_encoding_long_name_2); tcase_add_test(tc_basic, test_invalid_unknown_encoding); + tcase_add_test(tc_basic, test_unknown_ascii_encoding_ok); suite_add_tcase(s, tc_namespace); tcase_add_checked_fixture(tc_namespace,