Test bad start of name with an unknown encoding

This commit is contained in:
Rhodri James 2017-06-08 19:48:43 +01:00 committed by Sebastian Pipping
parent e8999ace2e
commit edc300c876

View File

@ -5283,8 +5283,11 @@ failing_converter(void *UNUSED_P(data), const char *UNUSED_P(s))
static int XMLCALL
prefix_converter(void *UNUSED_P(data), const char *s)
{
/* If the first byte is 0xff, raise an error */
if (s[0] == -1)
return -1;
/* Just add the low bits of the first byte to the second */
return s[1] + (s[0] & 0x7f);
return (s[1] + (s[0] & 0x7f)) & 0x01ff;
}
static int XMLCALL
@ -5367,6 +5370,20 @@ START_TEST(test_unknown_encoding_success)
}
END_TEST
/* Test bad name character in unknown encoding */
START_TEST(test_unknown_encoding_bad_name)
{
const char *text =
"<?xml version='1.0' encoding='experimental'?>\n"
"<\xff\x64oc>Hello, world</\xff\x64oc>";
XML_SetUnknownEncodingHandler(parser, BadEncodingHandler,
(void *)PREFIX_CONVERTER);
expect_failure(text, XML_ERROR_INVALID_TOKEN,
"Bad name start in unknown encoding not faulted");
}
END_TEST
/* Be tidy */
#undef NO_CONVERTER
#undef FAILING_CONVERTER
@ -10631,6 +10648,7 @@ make_suite(void)
tcase_add_test(tc_basic, test_missing_encoding_conversion_fn);
tcase_add_test(tc_basic, test_failing_encoding_conversion_fn);
tcase_add_test(tc_basic, test_unknown_encoding_success);
tcase_add_test(tc_basic, test_unknown_encoding_bad_name);
suite_add_tcase(s, tc_namespace);
tcase_add_checked_fixture(tc_namespace,