mirror of
https://github.com/libexpat/libexpat.git
synced 2025-04-05 13:14:59 +00:00
Merge pull request #930 from libexpat/tests-cover-indirect-entity-recursion
Tests: Cover indirect entity recursion
This commit is contained in:
commit
a0dc7d5efa
1 changed files with 74 additions and 0 deletions
|
@ -1202,6 +1202,79 @@ START_TEST(test_wfc_no_recursive_entity_refs) {
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_no_indirectly_recursive_entity_refs) {
|
||||
struct TestCase {
|
||||
const char *doc;
|
||||
bool usesParameterEntities;
|
||||
};
|
||||
|
||||
const struct TestCase cases[] = {
|
||||
// general entity + character data
|
||||
{"<!DOCTYPE a [\n"
|
||||
" <!ENTITY e1 '&e2;'>\n"
|
||||
" <!ENTITY e2 '&e1;'>\n"
|
||||
"]><a>&e2;</a>\n",
|
||||
false},
|
||||
|
||||
// general entity + attribute value
|
||||
{"<!DOCTYPE a [\n"
|
||||
" <!ENTITY e1 '&e2;'>\n"
|
||||
" <!ENTITY e2 '&e1;'>\n"
|
||||
"]><a k1='&e2;' />\n",
|
||||
false},
|
||||
|
||||
// parameter entity
|
||||
{"<!DOCTYPE doc [\n"
|
||||
" <!ENTITY % p1 '%p2;'>\n"
|
||||
" <!ENTITY % p2 '%p1;'>\n"
|
||||
" <!ENTITY % define_g \"<!ENTITY g '%p2;'>\">\n"
|
||||
" %define_g;\n"
|
||||
"]>\n"
|
||||
"<doc/>\n",
|
||||
true},
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
|
||||
const char *const doc = cases[i].doc;
|
||||
const bool usesParameterEntities = cases[i].usesParameterEntities;
|
||||
|
||||
set_subtest("[%i] %s", (int)i, doc);
|
||||
|
||||
#ifdef XML_DTD // both GE and DTD
|
||||
const bool rejection_expected = true;
|
||||
#elif XML_GE == 1 // GE but not DTD
|
||||
const bool rejection_expected = ! usesParameterEntities;
|
||||
#else // neither DTD nor GE
|
||||
const bool rejection_expected = false;
|
||||
#endif
|
||||
|
||||
XML_Parser parser = XML_ParserCreate(NULL);
|
||||
|
||||
#ifdef XML_DTD
|
||||
if (usesParameterEntities) {
|
||||
assert_true(
|
||||
XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS)
|
||||
== 1);
|
||||
}
|
||||
#else
|
||||
UNUSED_P(usesParameterEntities);
|
||||
#endif // XML_DTD
|
||||
|
||||
const enum XML_Status status
|
||||
= _XML_Parse_SINGLE_BYTES(parser, doc, (int)strlen(doc),
|
||||
/*isFinal*/ XML_TRUE);
|
||||
|
||||
if (rejection_expected) {
|
||||
assert_true(status == XML_STATUS_ERROR);
|
||||
assert_true(XML_GetErrorCode(parser) == XML_ERROR_RECURSIVE_ENTITY_REF);
|
||||
} else {
|
||||
assert_true(status == XML_STATUS_OK);
|
||||
}
|
||||
|
||||
XML_ParserFree(parser);
|
||||
}
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_recursive_external_parameter_entity_2) {
|
||||
struct TestCase {
|
||||
const char *doc;
|
||||
|
@ -5996,6 +6069,7 @@ make_basic_test_case(Suite *s) {
|
|||
tcase_add_test(tc_basic, test_not_standalone_handler_reject);
|
||||
tcase_add_test(tc_basic, test_not_standalone_handler_accept);
|
||||
tcase_add_test__if_xml_ge(tc_basic, test_wfc_no_recursive_entity_refs);
|
||||
tcase_add_test(tc_basic, test_no_indirectly_recursive_entity_refs);
|
||||
tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_invalid_parse);
|
||||
tcase_add_test__if_xml_ge(tc_basic, test_dtd_default_handling);
|
||||
tcase_add_test(tc_basic, test_dtd_attr_handling);
|
||||
|
|
Loading…
Add table
Reference in a new issue