From 28e9820bcd99f7914146b823e4a794f6db1d8e2e Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Fri, 17 Mar 2017 15:17:43 +0000 Subject: [PATCH] Test suspending and resuming parse in parameter entity substitution --- expat/tests/runtests.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index da0e2f40..54168a8f 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -4682,6 +4682,42 @@ START_TEST(test_suspend_resume_internal_entity) } END_TEST +/* Test suspending and resuming in a parameter entity substitution */ +static void XMLCALL +element_decl_suspender(void *UNUSED_P(userData), + const XML_Char *UNUSED_P(name), + XML_Content *model) +{ + XML_StopParser(parser, XML_TRUE); + XML_FreeContentModel(parser, model); +} + +START_TEST(test_suspend_resume_parameter_entity) +{ + const char *text = + "'>\n" + "%foo;\n" + "]>\n" + "Hello, world"; + const char *expected = "Hello, world"; + CharData storage; + + CharData_Init(&storage); + XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetElementDeclHandler(parser, element_decl_suspender); + XML_SetCharacterDataHandler(parser, accumulate_characters); + XML_SetUserData(parser, &storage); + if (XML_Parse(parser, text, strlen(text), + XML_TRUE) != XML_STATUS_SUSPENDED) + xml_failure(parser); + CharData_CheckXMLChars(&storage, ""); + if (XML_ResumeParser(parser) != XML_STATUS_OK) + xml_failure(parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + /* * Namespaces tests. @@ -7952,6 +7988,7 @@ make_suite(void) tcase_add_test(tc_basic, test_partial_char_in_epilog); tcase_add_test(tc_basic, test_hash_collision); tcase_add_test(tc_basic, test_suspend_resume_internal_entity); + tcase_add_test(tc_basic, test_suspend_resume_parameter_entity); suite_add_tcase(s, tc_namespace); tcase_add_checked_fixture(tc_namespace, -- 2.40.0