Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ lyjson_string(struct lyjson_ctx *jsonctx)
/* Basic Multilingual Plane character \uXXXX */
ADD_CHECK_OVERFLOW_GOTO(offset, 1, error);
for (value = i = 0; i < 4; i++) {
if (!in[offset + i]) {
LOGVAL(jsonctx->ctx, NULL, LYVE_SYNTAX, "Invalid basic multilingual plane character \"%s\".", c);
if (!isxdigit(in[offset + i])) {
LOGVAL(jsonctx->ctx, NULL, LYVE_SYNTAX, "Invalid basic multilingual plane character \"%.6s\".", c);
goto error;
} else if (isdigit(in[offset + i])) {
u = (in[offset + i] - '0');
Expand Down
19 changes: 19 additions & 0 deletions tests/utests/basic/test_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,25 @@ test_string(void **state)
CHECK_LOG_CTX("Missing quotation-mark at the end of a JSON string.", NULL, 1);
CHECK_LOG_CTX("Unexpected end-of-input.", NULL, 1);

/* escaped character */
str = "\"\\u003c\\u003C\"";
assert_non_null(ly_in_memory(in, str));
assert_int_equal(LY_SUCCESS, lyd_parse_value_fragment(ctx, "/test:l", in, LYD_JSON, 0, 0, 0, &tree));
assert_string_equal("<<", lyd_get_value(tree));
lyd_free_all(tree);
tree = NULL;

/* non-hexadecimal digits in an escaped character */
str = "\"\\u002s\"";
assert_non_null(ly_in_memory(in, str));
assert_int_equal(LY_EVALID, lyd_parse_value_fragment(ctx, "/test:l", in, LYD_JSON, 0, 0, 0, &tree));
CHECK_LOG_CTX("Invalid basic multilingual plane character \"\\u002s\".", NULL, 1);

str = "\"\\u004\"\"";
assert_non_null(ly_in_memory(in, str));
assert_int_equal(LY_EVALID, lyd_parse_value_fragment(ctx, "/test:l", in, LYD_JSON, 0, 0, 0, &tree));
CHECK_LOG_CTX("Invalid basic multilingual plane character \"\\u004\"\".", NULL, 1);

ly_in_free(in, 0);
}

Expand Down
Loading