From 80552b5c60dba403c0eb014738dfbeb662bd8d89 Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Wed, 15 Mar 2017 15:53:46 +0000 Subject: [PATCH] Test skipped parameter entity in external DTD triggers handler --- expat/tests/runtests.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index 729dbedd..06045811 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -146,6 +146,7 @@ static unsigned long dummy_handler_flags = 0; #define DUMMY_END_NS_DECL_HANDLER_FLAG (1UL << 13) #define DUMMY_START_DOCTYPE_DECL_HANDLER_FLAG (1UL << 14) #define DUMMY_END_DOCTYPE_DECL_HANDLER_FLAG (1UL << 15) +#define DUMMY_SKIP_HANDLER_FLAG (1UL << 16) static void XMLCALL @@ -311,6 +312,14 @@ dummy_end_doctype_decl_handler(void *UNUSED_P(userData)) dummy_handler_flags |= DUMMY_END_DOCTYPE_DECL_HANDLER_FLAG; } +static void XMLCALL +dummy_skip_handler(void *UNUSED_P(userData), + const XML_Char *UNUSED_P(entityName), + int UNUSED_P(is_parameter_entity)) +{ + dummy_handler_flags |= DUMMY_SKIP_HANDLER_FLAG; +} + /* * Character & encoding tests. */ @@ -4285,6 +4294,32 @@ START_TEST(test_group_choice) } END_TEST +/* Test skipping of parameter entity in an external DTD */ +/* Derived from ibm/invalid/P69/ibm69i01.xml */ +START_TEST(test_skipped_parameter_entity) +{ + const char *text = + "\n" + "\n" + "]>\n" + ""; + ExtTest dtd_data = { "%pe2;", NULL, NULL }; + + XML_SetExternalEntityRefHandler(parser, external_entity_loader); + XML_SetUserData(parser, &dtd_data); + XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetSkippedEntityHandler(parser, dummy_skip_handler); + dummy_handler_flags = 0; + if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text), + XML_TRUE) == XML_STATUS_ERROR) + xml_failure(parser); + if (dummy_handler_flags != DUMMY_SKIP_HANDLER_FLAG) + fail("Skip handler not executed"); +} +END_TEST + + /* * Namespaces tests. */ @@ -7434,6 +7469,7 @@ make_suite(void) tcase_add_test(tc_basic, test_nested_groups); tcase_add_test(tc_basic, test_group_choice); tcase_add_test(tc_basic, test_standalone_parameter_entity); + tcase_add_test(tc_basic, test_skipped_parameter_entity); suite_add_tcase(s, tc_namespace); tcase_add_checked_fixture(tc_namespace,