plugins types CHANGE print the offending length string
diff --git a/src/common.h b/src/common.h
index 32b6a1b..6e174c7 100644
--- a/src/common.h
+++ b/src/common.h
@@ -285,7 +285,7 @@
#define LY_VCODE_NOKEY LYVE_DATA, "List instance is missing its key \"%s\"."
#define LY_ERRMSG_NOPATTERN /* LYVE_DATA */ "Unsatisfied pattern - \"%.*s\" does not conform to %s\"%s\"."
-#define LY_ERRMSG_NOLENGTH /* LYVE_DATA */ "Unsatisfied length - string length \"%.*s\" is not allowed."
+#define LY_ERRMSG_NOLENGTH /* LYVE_DATA */ "Unsatisfied length - string \"%.*s\" length is not allowed."
#define LY_ERRMSG_NORANGE /* LYVE_DATA */ "Unsatisfied range - value \"%.*s\" is out of the allowed range."
/* RFC 7950 section 15 errors */
diff --git a/src/plugins_types/ipv6_address.c b/src/plugins_types/ipv6_address.c
index 0af4a64..8cd7938 100644
--- a/src/plugins_types/ipv6_address.c
+++ b/src/plugins_types/ipv6_address.c
@@ -141,12 +141,8 @@
/* length restriction of the string */
if (type_str->length) {
- char buf[LY_NUMBER_MAXLEN];
- size_t char_count = ly_utf8len(value, value_len);
-
/* value_len is in bytes, but we need number of characters here */
- snprintf(buf, LY_NUMBER_MAXLEN, "%zu", char_count);
- ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, char_count, buf, strlen(buf), err);
+ ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
LY_CHECK_GOTO(ret, cleanup);
}
diff --git a/src/plugins_types/string.c b/src/plugins_types/string.c
index 64ab544..071a622 100644
--- a/src/plugins_types/string.c
+++ b/src/plugins_types/string.c
@@ -42,12 +42,8 @@
/* length restriction of the string */
if (type_str->length) {
- char buf[LY_NUMBER_MAXLEN];
- size_t char_count = ly_utf8len(value, value_len);
-
/* value_len is in bytes, but we need number of characters here */
- snprintf(buf, LY_NUMBER_MAXLEN, "%zu", char_count);
- ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, char_count, buf, strlen(buf), err);
+ ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
}
diff --git a/tests/utests/types/string.c b/tests/utests/types/string.c
index cbd52d5..749d084 100644
--- a/tests/utests/types/string.c
+++ b/tests/utests/types/string.c
@@ -741,7 +741,7 @@
TEST_SUCCESS_XML("T1", "abc-de", STRING, "abc-de");
/* ERROR LENGTH */
TEST_ERROR_XML("T1", "p4a<");
- CHECK_LOG_CTX("Unsatisfied length - string length \"4\" is not allowed.",
+ CHECK_LOG_CTX("Unsatisfied length - string \"p4a<\" length is not allowed.",
"Schema location /T1:port, line number 1.");
/* TEST DEFAULT VALUE */
@@ -785,7 +785,7 @@
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
TEST_SUCCESS_XML("T_UTF8", "€€€€€", STRING, "€€€€€");
TEST_ERROR_XML("T_UTF8", "€€€");
- CHECK_LOG_CTX("Unsatisfied length - string length \"3\" is not allowed.",
+ CHECK_LOG_CTX("Unsatisfied length - string \"€€€\" length is not allowed.",
"Schema location /T_UTF8:port, line number 1.");
TEST_ERROR_XML("T_UTF8", "€€€€€€€€");
CHECK_LOG_CTX("Unsatisfied pattern - \"€€€€€€€€\" does not conform to \"[€]{5,7}\".",
@@ -869,7 +869,7 @@
TEST_SUCCESS_JSON("T1", "abc\\n-de", STRING, "abc\n-de");
/* ERROR LENGTH */
TEST_ERROR_JSON("T1", "p4a\u042F");
- CHECK_LOG_CTX("Unsatisfied length - string length \"4\" is not allowed.",
+ CHECK_LOG_CTX("Unsatisfied length - string \"p4aЯ\" length is not allowed.",
"Schema location /T1:port, line number 1.");
/* TEST DEFAULT VALUE */
@@ -907,7 +907,7 @@
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
TEST_SUCCESS_JSON("T_UTF8", "€€€€€", STRING, "€€€€€");
TEST_ERROR_JSON("T_UTF8", "€€€");
- CHECK_LOG_CTX("Unsatisfied length - string length \"3\" is not allowed.",
+ CHECK_LOG_CTX("Unsatisfied length - string \"€€€\" length is not allowed.",
"Schema location /T_UTF8:port, line number 1.");
TEST_ERROR_JSON("T_UTF8", "€€€€€€€€");
CHECK_LOG_CTX("Unsatisfied pattern - \"€€€€€€€€\" does not conform to \"[€]{5,7}\".",
@@ -977,7 +977,7 @@
"yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\" 555 555\">"
"121</port>";
CHECK_PARSE_LYD_PARAM(diff_expected, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, model_1);
- CHECK_LOG_CTX("Unsatisfied length - string length \"3\" is not allowed.",
+ CHECK_LOG_CTX("Unsatisfied length - string \"121\" length is not allowed.",
"Schema location /T_DIFF:port, line number 1.");
/* diff from default value */