From: Rhodri James Date: Wed, 1 Feb 2017 14:51:23 +0000 (+0000) Subject: Test that unrecognised encodings are rejected X-Git-Tag: R_2_2_1~143 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a085b6bc3a493995bb9bf6da56685e63f5c8375a;p=libexpat Test that unrecognised encodings are rejected --- diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index 79368dd6..74fb1c91 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -855,6 +855,37 @@ START_TEST(test_unknown_encoding_internal_entity) } END_TEST +/* Test unrecognised encoding handler */ +static void dummy_release(void *UNUSED_P(data)) +{ +} + +static int XMLCALL +UnrecognisedEncodingHandler(void *UNUSED_P(data), + const XML_Char *UNUSED_P(encoding), + XML_Encoding *info) +{ + info->data = NULL; + info->convert = NULL; + info->release = dummy_release; + return XML_STATUS_ERROR; +} + +START_TEST(test_unrecognised_encoding_internal_entity) +{ + const char *text = + "\n" + "]>\n" + ""; + + XML_SetUnknownEncodingHandler(parser, + UnrecognisedEncodingHandler, + NULL); + if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text), XML_TRUE) != XML_STATUS_ERROR) + fail("Unrecognised encoding not rejected"); +} +END_TEST + /* Regression test for SF bug #620106. */ static int XMLCALL external_entity_loader_set_encoding(XML_Parser parser, @@ -1871,10 +1902,6 @@ START_TEST(test_alloc_ns) } END_TEST -static void dummy_release(void *UNUSED_P(data)) -{ -} - static int XMLCALL unknown_released_encoding_handler(void *UNUSED_P(data), const XML_Char *encoding, @@ -1971,6 +1998,7 @@ make_suite(void) tcase_add_test(tc_basic, test_attr_whitespace_normalization); tcase_add_test(tc_basic, test_xmldecl_misplaced); tcase_add_test(tc_basic, test_unknown_encoding_internal_entity); + tcase_add_test(tc_basic, test_unrecognised_encoding_internal_entity); tcase_add_test(tc_basic, test_wfc_undeclared_entity_unread_external_subset); tcase_add_test(tc_basic, test_wfc_undeclared_entity_no_external_subset);