]> granicus.if.org Git - libexpat/commitdiff
Add test for encoding conversion function returning errors
authorRhodri James <rhodri@kynesim.co.uk>
Tue, 6 Jun 2017 17:40:50 +0000 (18:40 +0100)
committerSebastian Pipping <sebastian@pipping.org>
Sat, 22 Jul 2017 20:49:17 +0000 (22:49 +0200)
expat/tests/runtests.c

index 1e0a52c5708b979b61346e9c16526190b07166f3..c1e242123e24f09f7ad600bcc501c172688df74d 100644 (file)
@@ -5304,6 +5304,31 @@ START_TEST(test_missing_encoding_conversion_fn)
 }
 END_TEST
 
+static int XMLCALL
+failing_converter(void *UNUSED_P(data), const char *UNUSED_P(s))
+{
+    /* Always claim to have failed */
+    return -1;
+}
+
+START_TEST(test_failing_encoding_conversion_fn)
+{
+    const char *text =
+        "<?xml version='1.0' encoding='experimental'?>\n"
+        "<doc>\x81</doc>";
+
+    XML_SetUnknownEncodingHandler(parser, BadEncodingHandler,
+                                  (void *)failing_converter);
+    /* BadEncodingHandler sets up an encoding with every top-bit-set
+     * character introducing a two-byte sequence.  For this, it
+     * requires a convert function.  The above function call passes
+     * one that insists all possible sequences are invalid anyway.
+     */
+    expect_failure(text, XML_ERROR_INVALID_TOKEN,
+                   "Encoding with failing convert() not faulted");
+}
+END_TEST
+
 
 /*
  * Namespaces tests.
@@ -10562,6 +10587,7 @@ make_suite(void)
     tcase_add_test(tc_basic, test_pi_handled_in_default);
     tcase_add_test(tc_basic, test_comment_handled_in_default);
     tcase_add_test(tc_basic, test_missing_encoding_conversion_fn);
+    tcase_add_test(tc_basic, test_failing_encoding_conversion_fn);
 
     suite_add_tcase(s, tc_namespace);
     tcase_add_checked_fixture(tc_namespace,