summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfdrake <fdrake>2006-07-01 15:30:37 +0000
committerfdrake <fdrake>2006-07-01 15:30:37 +0000
commitff873b01468af7910d7695c033784ed40ac01d49 (patch)
tree00b1d660c19447c452593f43df6692aa6bad6846
parent017a4cbd7ee2aeb22a3e1c41f0f6f85917613ca6 (diff)
downloadlibexpat-ff873b01468af7910d7695c033784ed40ac01d49.tar.gz
SF bug #1515266: as noted, suspending the parser has the same problem that
the abort code has; added a check and regression test or that
-rw-r--r--lib/xmlparse.c2
-rw-r--r--tests/runtests.c92
2 files changed, 60 insertions, 34 deletions
diff --git a/lib/xmlparse.c b/lib/xmlparse.c
index 10236fa..5df6464 100644
--- a/lib/xmlparse.c
+++ b/lib/xmlparse.c
@@ -2555,7 +2555,7 @@ doContent(XML_Parser parser,
(int)(dataPtr - (ICHAR *)dataBuf));
if (s == next)
break;
- if (ps_parsing == XML_FINISHED)
+ if (ps_parsing == XML_FINISHED || ps_parsing == XML_SUSPENDED)
break;
*eventPP = s;
}
diff --git a/tests/runtests.c b/tests/runtests.c
index 23b92ad..fdb33c2 100644
--- a/tests/runtests.c
+++ b/tests/runtests.c
@@ -53,10 +53,12 @@ static void
_xml_failure(XML_Parser parser, const char *file, int line)
{
char buffer[1024];
+ enum XML_Error err = XML_GetErrorCode(parser);
sprintf(buffer,
- "\n %s (line %" XML_FMT_INT_MOD "u, offset %"\
- XML_FMT_INT_MOD "u)\n reported from %s, line %d",
- XML_ErrorString(XML_GetErrorCode(parser)),
+ " %d: %s (line %" XML_FMT_INT_MOD "u, offset %"\
+ XML_FMT_INT_MOD "u)\n reported from %s, line %d\n",
+ err,
+ XML_ErrorString(err),
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser),
file, line);
@@ -982,13 +984,37 @@ START_TEST(test_ns_in_attribute_default_without_namespaces)
}
END_TEST
+static char *long_character_data_text =
+ "<?xml version='1.0' encoding='iso-8859-1'?><s>"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "</s>";
+
+static XML_Bool resumable = XML_FALSE;
static void
-self_clearing_aborting_character_handler(void *userData,
- const XML_Char *s,
- int len)
+clearing_aborting_character_handler(void *userData,
+ const XML_Char *s, int len)
{
- XML_StopParser(parser, XML_FALSE);
+ XML_StopParser(parser, resumable);
XML_SetCharacterDataHandler(parser, NULL);
}
@@ -1002,32 +1028,10 @@ START_TEST(test_stop_parser_between_char_data_calls)
handler must stop the parser and clear the character data
handler.
*/
- char *text =
- "<?xml version='1.0' encoding='iso-8859-1'?><s>"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "012345678901234567890123456789012345678901234567890123456789"
- "</s>";
-
- XML_SetCharacterDataHandler(parser,
- self_clearing_aborting_character_handler);
+ char *text = long_character_data_text;
+
+ XML_SetCharacterDataHandler(parser, clearing_aborting_character_handler);
+ resumable = XML_FALSE;
if (XML_Parse(parser, text, strlen(text), XML_TRUE) != XML_STATUS_ERROR)
xml_failure(parser);
if (XML_GetErrorCode(parser) != XML_ERROR_ABORTED)
@@ -1035,6 +1039,27 @@ START_TEST(test_stop_parser_between_char_data_calls)
}
END_TEST
+/* Regression test for SF bug #1515266: missing check of stopped
+ parser in doContext() 'for' loop. */
+START_TEST(test_suspend_parser_between_char_data_calls)
+{
+ /* The sample data must be big enough that there are two calls to
+ the character data handler from within the inner "for" loop of
+ the XML_TOK_DATA_CHARS case in doContent(), and the character
+ handler must stop the parser and clear the character data
+ handler.
+ */
+ char *text = long_character_data_text;
+
+ XML_SetCharacterDataHandler(parser, clearing_aborting_character_handler);
+ resumable = XML_TRUE;
+ if (XML_Parse(parser, text, strlen(text), XML_TRUE) != XML_STATUS_SUSPENDED)
+ xml_failure(parser);
+ if (XML_GetErrorCode(parser) != XML_ERROR_NONE)
+ xml_failure(parser);
+}
+END_TEST
+
/*
* Namespaces tests.
@@ -1434,6 +1459,7 @@ make_suite(void)
tcase_add_test(tc_basic, test_empty_ns_without_namespaces);
tcase_add_test(tc_basic, test_ns_in_attribute_default_without_namespaces);
tcase_add_test(tc_basic, test_stop_parser_between_char_data_calls);
+ tcase_add_test(tc_basic, test_suspend_parser_between_char_data_calls);
suite_add_tcase(s, tc_namespace);
tcase_add_checked_fixture(tc_namespace,