}
END_TEST
+/* Test external entity fault handling with suspension */
+static int XMLCALL
+external_entity_suspending_faulter(XML_Parser parser,
+ const XML_Char *context,
+ const XML_Char *UNUSED_P(base),
+ const XML_Char *UNUSED_P(systemId),
+ const XML_Char *UNUSED_P(publicId))
+{
+ XML_Parser ext_parser;
+ ExtFaults *fault = (ExtFaults *)XML_GetUserData(parser);
+ void *buffer;
+ int parse_len = strlen(fault->parse_text);
+
+ ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL);
+ if (ext_parser == NULL)
+ fail("Could not create external entity parser");
+ XML_SetXmlDeclHandler(ext_parser, entity_suspending_xdecl_handler);
+ XML_SetUserData(ext_parser, ext_parser);
+ resumable = XML_TRUE;
+ buffer = XML_GetBuffer(ext_parser, parse_len);
+ if (buffer == NULL)
+ fail("Could not allocate parse buffer");
+ memcpy(buffer, fault->parse_text, parse_len);
+ if (XML_ParseBuffer(ext_parser, parse_len,
+ XML_FALSE) != XML_STATUS_SUSPENDED)
+ fail("XML declaration did not suspend");
+ if (XML_ResumeParser(ext_parser) != XML_STATUS_OK)
+ xml_failure(ext_parser);
+ if (XML_ParseBuffer(ext_parser, 0, XML_TRUE) != XML_STATUS_ERROR)
+ fail(fault->fail_text);
+ if (XML_GetErrorCode(ext_parser) != fault->error)
+ xml_failure(ext_parser);
+ return XML_STATUS_ERROR;
+}
+
+START_TEST(test_ext_entity_invalid_suspended_parse)
+{
+ const char *text =
+ "<!DOCTYPE doc [\n"
+ " <!ENTITY en SYSTEM 'http://xml.libexpat.org/dummy.ent'>\n"
+ "]>\n"
+ "<doc>&en;</doc>";
+ ExtFaults faults[] = {
+ {
+ "<?xml version='1.0' encoding='us-ascii'?><",
+ "Incomplete element declaration not faulted",
+ XML_ERROR_UNCLOSED_TOKEN
+ },
+ {
+ /* First two bytes of a three-byte char */
+ "<?xml version='1.0' encoding='utf-8'?>\xe2\x82",
+ "Incomplete character not faulted",
+ XML_ERROR_PARTIAL_CHAR
+ },
+ { NULL, NULL, XML_ERROR_NONE }
+ };
+ ExtFaults *fault;
+
+ for (fault = &faults[0]; fault->parse_text != NULL; fault++) {
+ XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
+ XML_SetExternalEntityRefHandler(parser,
+ external_entity_suspending_faulter);
+ XML_SetUserData(parser, fault);
+ expect_failure(text,
+ XML_ERROR_EXTERNAL_ENTITY_HANDLING,
+ "Parser did not report external entity error");
+ XML_ParserReset(parser, NULL);
+ }
+}
+END_TEST
+
+
/* Test setting an explicit encoding */
START_TEST(test_explicit_encoding)
tcase_add_test(tc_basic, test_ext_entity_set_bom);
tcase_add_test(tc_basic, test_ext_entity_bad_encoding);
tcase_add_test(tc_basic, test_ext_entity_invalid_parse);
+ tcase_add_test(tc_basic, test_ext_entity_invalid_suspended_parse);
tcase_add_test(tc_basic, test_dtd_default_handling);
tcase_add_test(tc_basic, test_empty_ns_without_namespaces);
tcase_add_test(tc_basic, test_ns_in_attribute_default_without_namespaces);