From: Rhodri James Date: Fri, 9 Jun 2017 12:14:43 +0000 (+0100) Subject: Test unknown encoding not compatible with ASCII is rejected X-Git-Tag: R_2_2_3~22^2~85 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=32ade2af4060a2660d0b34df7a71eecceda53a4f;p=libexpat Test unknown encoding not compatible with ASCII is rejected --- diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index 8a4441d0..db454664 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -5453,6 +5453,36 @@ END_TEST #undef FAILING_CONVERTER #undef PREFIX_CONVERTER +static int XMLCALL +InvalidEncodingHandler(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; + info->map[9] = 5; /* Not a valid setting: ASCII must map to ASCII */ + info->data = NULL; + info->convert = NULL; + info->release = NULL; + return XML_STATUS_OK; +} + +START_TEST(test_invalid_unknown_encoding) +{ + const char *text = + "\n" + "Hello world"; + + XML_SetUnknownEncodingHandler(parser, InvalidEncodingHandler, NULL); + expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, + "Invalid unknown encoding not faulted"); +} +END_TEST + /* * Namespaces tests. */ @@ -10716,6 +10746,7 @@ make_suite(void) tcase_add_test(tc_basic, test_unknown_encoding_bad_name_2); 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); suite_add_tcase(s, tc_namespace); tcase_add_checked_fixture(tc_namespace,