mirror of
https://github.com/libexpat/libexpat.git
synced 2025-04-07 22:19:12 +00:00
Move test_ext_entity_not_standalone out of runtests.c
This commit is contained in:
parent
07b7a9f4fc
commit
8d3fe6ce74
4 changed files with 56 additions and 50 deletions
|
@ -2992,6 +2992,18 @@ START_TEST(test_external_entity_values) {
|
|||
}
|
||||
END_TEST
|
||||
|
||||
/* Test the recursive parse interacts with a not standalone handler */
|
||||
START_TEST(test_ext_entity_not_standalone) {
|
||||
const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n"
|
||||
"<doc></doc>";
|
||||
|
||||
XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
|
||||
XML_SetExternalEntityRefHandler(g_parser, external_entity_not_standalone);
|
||||
expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING,
|
||||
"Standalone rejection not caught");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
TCase *
|
||||
make_basic_test_case(Suite *s) {
|
||||
TCase *tc_basic = tcase_create("basic tests");
|
||||
|
@ -3123,6 +3135,7 @@ make_basic_test_case(Suite *s) {
|
|||
tcase_add_test__ifdef_xml_dtd(tc_basic, test_ignore_section_utf16_be);
|
||||
tcase_add_test__ifdef_xml_dtd(tc_basic, test_bad_ignore_section);
|
||||
tcase_add_test__ifdef_xml_dtd(tc_basic, test_external_entity_values);
|
||||
tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_not_standalone);
|
||||
|
||||
return tc_basic; /* TEMPORARY: this will become a void function */
|
||||
}
|
||||
|
|
|
@ -773,6 +773,43 @@ external_entity_valuer(XML_Parser parser, const XML_Char *context,
|
|||
return XML_STATUS_OK;
|
||||
}
|
||||
|
||||
int XMLCALL
|
||||
external_entity_not_standalone(XML_Parser parser, const XML_Char *context,
|
||||
const XML_Char *base, const XML_Char *systemId,
|
||||
const XML_Char *publicId) {
|
||||
const char *text1 = "<!ELEMENT doc EMPTY>\n"
|
||||
"<!ENTITY % e1 SYSTEM 'bar'>\n"
|
||||
"%e1;\n";
|
||||
const char *text2 = "<!ATTLIST doc a1 CDATA 'value'>";
|
||||
XML_Parser ext_parser;
|
||||
|
||||
UNUSED_P(base);
|
||||
UNUSED_P(publicId);
|
||||
if (systemId == NULL)
|
||||
return XML_STATUS_OK;
|
||||
ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL);
|
||||
if (ext_parser == NULL)
|
||||
fail("Could not create external entity parser");
|
||||
if (! xcstrcmp(systemId, XCS("foo"))) {
|
||||
XML_SetNotStandaloneHandler(ext_parser, reject_not_standalone_handler);
|
||||
if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE)
|
||||
!= XML_STATUS_ERROR)
|
||||
fail("Expected not standalone rejection");
|
||||
if (XML_GetErrorCode(ext_parser) != XML_ERROR_NOT_STANDALONE)
|
||||
xml_failure(ext_parser);
|
||||
XML_SetNotStandaloneHandler(ext_parser, NULL);
|
||||
XML_ParserFree(ext_parser);
|
||||
return XML_STATUS_ERROR;
|
||||
} else if (! xcstrcmp(systemId, XCS("bar"))) {
|
||||
if (_XML_Parse_SINGLE_BYTES(ext_parser, text2, (int)strlen(text2), XML_TRUE)
|
||||
== XML_STATUS_ERROR)
|
||||
xml_failure(ext_parser);
|
||||
}
|
||||
|
||||
XML_ParserFree(ext_parser);
|
||||
return XML_STATUS_OK;
|
||||
}
|
||||
|
||||
/* NotStandalone handlers */
|
||||
|
||||
int XMLCALL
|
||||
|
|
|
@ -242,6 +242,12 @@ extern int XMLCALL external_entity_valuer(XML_Parser parser,
|
|||
const XML_Char *systemId,
|
||||
const XML_Char *publicId);
|
||||
|
||||
extern int XMLCALL external_entity_not_standalone(XML_Parser parser,
|
||||
const XML_Char *context,
|
||||
const XML_Char *base,
|
||||
const XML_Char *systemId,
|
||||
const XML_Char *publicId);
|
||||
|
||||
/* NotStandalone handlers */
|
||||
|
||||
extern int XMLCALL reject_not_standalone_handler(void *userData);
|
||||
|
|
|
@ -74,55 +74,6 @@
|
|||
|
||||
XML_Parser g_parser = NULL;
|
||||
|
||||
/* Test the recursive parse interacts with a not standalone handler */
|
||||
static int XMLCALL
|
||||
external_entity_not_standalone(XML_Parser parser, const XML_Char *context,
|
||||
const XML_Char *base, const XML_Char *systemId,
|
||||
const XML_Char *publicId) {
|
||||
const char *text1 = "<!ELEMENT doc EMPTY>\n"
|
||||
"<!ENTITY % e1 SYSTEM 'bar'>\n"
|
||||
"%e1;\n";
|
||||
const char *text2 = "<!ATTLIST doc a1 CDATA 'value'>";
|
||||
XML_Parser ext_parser;
|
||||
|
||||
UNUSED_P(base);
|
||||
UNUSED_P(publicId);
|
||||
if (systemId == NULL)
|
||||
return XML_STATUS_OK;
|
||||
ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL);
|
||||
if (ext_parser == NULL)
|
||||
fail("Could not create external entity parser");
|
||||
if (! xcstrcmp(systemId, XCS("foo"))) {
|
||||
XML_SetNotStandaloneHandler(ext_parser, reject_not_standalone_handler);
|
||||
if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE)
|
||||
!= XML_STATUS_ERROR)
|
||||
fail("Expected not standalone rejection");
|
||||
if (XML_GetErrorCode(ext_parser) != XML_ERROR_NOT_STANDALONE)
|
||||
xml_failure(ext_parser);
|
||||
XML_SetNotStandaloneHandler(ext_parser, NULL);
|
||||
XML_ParserFree(ext_parser);
|
||||
return XML_STATUS_ERROR;
|
||||
} else if (! xcstrcmp(systemId, XCS("bar"))) {
|
||||
if (_XML_Parse_SINGLE_BYTES(ext_parser, text2, (int)strlen(text2), XML_TRUE)
|
||||
== XML_STATUS_ERROR)
|
||||
xml_failure(ext_parser);
|
||||
}
|
||||
|
||||
XML_ParserFree(ext_parser);
|
||||
return XML_STATUS_OK;
|
||||
}
|
||||
|
||||
START_TEST(test_ext_entity_not_standalone) {
|
||||
const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n"
|
||||
"<doc></doc>";
|
||||
|
||||
XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
|
||||
XML_SetExternalEntityRefHandler(g_parser, external_entity_not_standalone);
|
||||
expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING,
|
||||
"Standalone rejection not caught");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static int XMLCALL
|
||||
external_entity_value_aborter(XML_Parser parser, const XML_Char *context,
|
||||
const XML_Char *base, const XML_Char *systemId,
|
||||
|
@ -7728,7 +7679,6 @@ make_suite(void) {
|
|||
TCase *tc_accounting = tcase_create("accounting tests");
|
||||
#endif
|
||||
|
||||
tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_not_standalone);
|
||||
tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_value_abort);
|
||||
tcase_add_test(tc_basic, test_bad_public_doctype);
|
||||
tcase_add_test(tc_basic, test_attribute_enum_value);
|
||||
|
|
Loading…
Add table
Reference in a new issue