tests CHANGE nehance xml tests - processing n-bytes UTF characters
diff --git a/src/xml.c b/src/xml.c
index 78b259f..bd26f16 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -168,7 +168,7 @@
* Includes checking for valid characters (following RFC 7950, sec 9.4)
*/
static LY_ERR
-lyxml_pututf8(char *dst, int32_t value, size_t *bytes_written)
+lyxml_pututf8(char *dst, uint32_t value, size_t *bytes_written)
{
if (value < 0x80) {
/* one byte character */
@@ -283,8 +283,8 @@
size_t len; /* write offset in output buffer */
size_t size; /* size of the output buffer */
void *p;
- int32_t n;
- size_t u;
+ uint32_t n;
+ size_t u, newlines;
bool empty_content = false;
LY_ERR rc;
@@ -302,8 +302,13 @@
if (empty_content) {
/* only when processing element's content - try to ignore whitespaces used to format XML data
* before element's child or closing tag */
- for (offset = 0; in[offset] && is_xmlws(in[offset]); ++offset);
+ for (offset = newlines = 0; in[offset] && is_xmlws(in[offset]); ++offset) {
+ if (in[offset] == '\n') {
+ ++newlines;
+ }
+ }
LY_CHECK_ERR_RET(!in[offset], LOGVAL(ctx, LY_VLOG_LINE, &context->line, LY_VCODE_EOF), LY_EVALID);
+ context->line += newlines;
if (in[offset] == '<') {
(*input) = in + offset;
return LY_EINVAL;
@@ -395,7 +400,7 @@
++offset;
rc = lyxml_pututf8(&buf[len], n, &u);
LY_CHECK_ERR_GOTO(rc, LOGVAL(ctx, LY_VLOG_LINE, &context->line, LYVE_SYNTAX,
- "Invalid character reference %.*s (0x%08x).", 12, p, n),
+ "Invalid character reference \"%.*s\" (0x%08x).", 12, p, n),
error);
len += u;
in += offset;
diff --git a/tests/src/xml.c b/tests/src/xml.c
index d299116..4ebdbbd 100644
--- a/tests/src/xml.c
+++ b/tests/src/xml.c
@@ -298,14 +298,14 @@
/* empty element content is invalid - missing content terminating character < */
str = "";
assert_int_equal(LY_EVALID, lyxml_get_string(&ctx, &str, &out, &out_len));
- logbuf_assert("Unexpected end-of-file. Line number 1.");
- str = p = "xxx";
+ logbuf_assert("Unexpected end-of-file. Line number 2.");
free(out);
out = NULL;
+ str = p = "xxx";
assert_int_equal(LY_EVALID, lyxml_get_string(&ctx, &str, &out, &out_len));
- logbuf_assert("Unexpected end-of-file. Line number 1.");
+ logbuf_assert("Unexpected end-of-file. Line number 2.");
assert_ptr_equal(p, str); /* input data not eaten */
free(out);
@@ -318,22 +318,40 @@
assert_string_equal("€𠜎Øn \n<&\"\'> ROK", out);
assert_string_equal("<", str);
+ /* test using n-bytes UTF8 hexadecimal code points */
+ str = "\'$¢€𐍈\'";
+ assert_int_equal(LY_SUCCESS, lyxml_get_string(&ctx, &str, &out, &out_len));
+ assert_string_equal("$¢€𐍈", out);
+
/* invalid characters in string */
str = p = "\'R\'";
assert_int_equal(LY_EVALID, lyxml_get_string(&ctx, &str, &out, &out_len));
- logbuf_assert("Invalid character sequence \"'\", expected ;. Line number 2.");
+ logbuf_assert("Invalid character sequence \"'\", expected ;. Line number 3.");
assert_ptr_equal(p, str); /* input data not eaten */
str = p = "\"R\"";
assert_int_equal(LY_EVALID, lyxml_get_string(&ctx, &str, &out, &out_len));
- logbuf_assert("Invalid character sequence \"\"\", expected ;. Line number 2.");
+ logbuf_assert("Invalid character sequence \"\"\", expected ;. Line number 3.");
assert_ptr_equal(p, str); /* input data not eaten */
str = p = "\"&nonsence;\"";
assert_int_equal(LY_EVALID, lyxml_get_string(&ctx, &str, &out, &out_len));
- logbuf_assert("Entity reference \"&nonsence;\" not supported, only predefined references allowed. Line number 2.");
+ logbuf_assert("Entity reference \"&nonsence;\" not supported, only predefined references allowed. Line number 3.");
assert_ptr_equal(p, str); /* input data not eaten */
str = p = "&#o122;";
assert_int_equal(LY_EVALID, lyxml_get_string(&ctx, &str, &out, &out_len));
- logbuf_assert("Invalid character reference \"&#o122;\". Line number 2.");
+ logbuf_assert("Invalid character reference \"&#o122;\". Line number 3.");
+ assert_ptr_equal(p, str); /* input data not eaten */
+
+ str = p = "\'\'";
+ assert_int_equal(LY_EVALID, lyxml_get_string(&ctx, &str, &out, &out_len));
+ logbuf_assert("Invalid character reference \"\'\" (0x00000006). Line number 3.");
+ assert_ptr_equal(p, str); /* input data not eaten */
+ str = p = "\'\'";
+ assert_int_equal(LY_EVALID, lyxml_get_string(&ctx, &str, &out, &out_len));
+ logbuf_assert("Invalid character reference \"\'\" (0x0000fdd0). Line number 3.");
+ assert_ptr_equal(p, str); /* input data not eaten */
+ str = p = "\'\'";
+ assert_int_equal(LY_EVALID, lyxml_get_string(&ctx, &str, &out, &out_len));
+ logbuf_assert("Invalid character reference \"\'\" (0x0000ffff). Line number 3.");
assert_ptr_equal(p, str); /* input data not eaten */
free(out);