]> granicus.if.org Git - libexpat/commitdiff
Test predefined entities
authorRhodri James <rhodri@kynesim.co.uk>
Mon, 13 Feb 2017 19:35:22 +0000 (19:35 +0000)
committerSebastian Pipping <sebastian@pipping.org>
Sun, 16 Jul 2017 21:02:30 +0000 (23:02 +0200)
expat/tests/runtests.c

index be77e62331387e380f6b0da0da93ba3c781ab98b..1d10358a1b874c8e6b78870ee7be3be3ac2b4ef5 100644 (file)
@@ -3386,6 +3386,31 @@ START_TEST(test_byte_info_at_cdata)
 }
 END_TEST
 
+/* Test predefined entities are correctly recognised */
+START_TEST(test_predefined_entities)
+{
+    const char *text = "<doc>&lt;&gt;&amp;&quot;&apos;</doc>";
+    const char *result = "<>&\"'";
+    CharData storage;
+
+    XML_SetDefaultHandler(parser, accumulate_characters);
+    /* run_character_check uses XML_SetCharacterDataHandler(), which
+     * unfortunately heads off a code path that we need to exercise.
+     */
+    CharData_Init(&storage);
+    XML_SetUserData(parser, &storage);
+    if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text),
+                                XML_TRUE) == XML_STATUS_ERROR)
+        xml_failure(parser);
+    /* The default handler doesn't translate the entities */
+    CharData_CheckXMLChars(&storage, text);
+
+    /* Now try again and check the translation */
+    XML_ParserReset(parser, NULL);
+    run_character_check(text, result);
+}
+END_TEST
+
 /* Regression test that an invalid tag in an external parameter
  * reference in an external DTD is correctly faulted.
  *
@@ -3532,6 +3557,7 @@ START_TEST(test_bad_ignore_section)
 }
 END_TEST
 
+
 /*
  * Namespaces tests.
  */
@@ -5609,6 +5635,7 @@ make_suite(void)
     tcase_add_test(tc_basic, test_byte_info_at_end);
     tcase_add_test(tc_basic, test_byte_info_at_error);
     tcase_add_test(tc_basic, test_byte_info_at_cdata);
+    tcase_add_test(tc_basic, test_predefined_entities);
     tcase_add_test(tc_basic, test_invalid_tag_in_dtd);
     tcase_add_test(tc_basic, test_ignore_section);
     tcase_add_test(tc_basic, test_bad_ignore_section);