From 4582daec8f7cf87a3a6188718f61947ea93749ee Mon Sep 17 00:00:00 2001 From: "Fred L. Drake, Jr." Date: Fri, 28 Jun 2002 23:04:49 +0000 Subject: [PATCH] Fix SF bug #575168: "Missing events for end-element". --- expat/lib/xmlparse.c | 7 ++++--- expat/tests/runtests.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/expat/lib/xmlparse.c b/expat/lib/xmlparse.c index cb4751c7..ffcdf196 100644 --- a/expat/lib/xmlparse.c +++ b/expat/lib/xmlparse.c @@ -1766,7 +1766,7 @@ doContent(XML_Parser parser, tag->rawName = tag->buf; } ++tagLevel; - if (startElementHandler) { + if (startElementHandler || endElementHandler) { enum XML_Error result; XML_Char *toPtr; for (;;) { @@ -1799,8 +1799,9 @@ doContent(XML_Parser parser, result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings)); if (result) return result; - startElementHandler(handlerArg, tag->name.str, - (const XML_Char **)atts); + if (startElementHandler) + startElementHandler(handlerArg, tag->name.str, + (const XML_Char **)atts); poolClear(&tempPool); } else { diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index f2e9c14f..27a6494c 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -285,6 +285,34 @@ START_TEST(test_line_count) END_TEST +/* + * Element event tests. + */ + +static void +end_element_event_handler(void *userData, const XML_Char *name) +{ + CharData *storage = (CharData *) userData; + CharData_AppendString(storage, "/"); + CharData_AppendXMLChars(storage, name, -1); +} + +START_TEST(test_end_element_events) +{ + char *text = ""; + char *expected = "/c/b/f/d/a"; + CharData storage; + + CharData_Init(&storage); + XML_SetUserData(parser, &storage); + XML_SetEndElementHandler(parser, end_element_event_handler); + if (!XML_Parse(parser, text, strlen(text), 1)) + xml_failure(parser); + CharData_CheckString(&storage, expected); +} +END_TEST + + /* * Attribute tests. */ @@ -578,6 +606,7 @@ make_basic_suite(void) TCase *tc_attrs = tcase_create("attributes"); TCase *tc_xmldecl = tcase_create("XML declaration"); TCase *tc_namespace = tcase_create("XML namespaces"); + TCase *tc_elements = tcase_create("element events"); suite_add_tcase(s, tc_chars); tcase_add_checked_fixture(tc_chars, basic_setup, basic_teardown); @@ -598,6 +627,10 @@ make_basic_suite(void) tcase_add_test(tc_chars, test_french_utf8); tcase_add_test(tc_chars, test_line_count); + suite_add_tcase(s, tc_elements); + tcase_add_checked_fixture(tc_elements, basic_setup, basic_teardown); + tcase_add_test(tc_elements, test_end_element_events); + suite_add_tcase(s, tc_attrs); tcase_add_checked_fixture(tc_attrs, basic_setup, basic_teardown); tcase_add_test(tc_attrs, test_attr_whitespace_normalization); -- 2.40.0