mirror of
https://github.com/MariaDB/server.git
synced 2026-10-23 18:49:29 +03:00
MDEV-40165: json_normalize (fix)
14c16e02b2 changed the
interface for json_normalize to take a json_engine_t so that
there could be some error checking.
Unfortunately ColumnStore depended on this interface.
Restored original interface of json_normalize() and
added a json_normalize_engine() that take as engine as the
argument.
This commit is contained in:
@@ -443,8 +443,10 @@ int json_locate_key(const char *js, const char *js_end,
|
||||
const char **key_start, const char **key_end,
|
||||
int *comma_pos);
|
||||
|
||||
int json_normalize(json_engine_t *je, DYNAMIC_STRING *result,
|
||||
int json_normalize(DYNAMIC_STRING *result,
|
||||
const char *s, size_t size, CHARSET_INFO *cs);
|
||||
int json_normalize_engine(json_engine_t *je, DYNAMIC_STRING *result,
|
||||
const char *s, size_t size, CHARSET_INFO *cs);
|
||||
|
||||
int json_skip_array_and_count(json_engine_t *j, int* n_item);
|
||||
|
||||
|
||||
@@ -650,11 +650,11 @@ bool Item_func_json_equals::val_bool()
|
||||
JSON_DO_PAUSE_EXECUTION(thd, 0.0002);
|
||||
je.killed_ptr= (uint32_t *) &thd->killed;
|
||||
|
||||
if (json_normalize(&je, &a_res, a->ptr(), a->length(), a->charset()))
|
||||
if (json_normalize_engine(&je, &a_res, a->ptr(), a->length(), a->charset()))
|
||||
goto return_null;
|
||||
|
||||
arg_num++;
|
||||
if (json_normalize(&je, &b_res, b->ptr(), b->length(), b->charset()))
|
||||
if (json_normalize_engine(&je, &b_res, b->ptr(), b->length(), b->charset()))
|
||||
goto return_null;
|
||||
|
||||
result= strcmp(a_res.str, b_res.str) ? 0 : 1;
|
||||
@@ -4620,9 +4620,9 @@ String *Item_func_json_normalize::val_str(String *buf)
|
||||
JSON_DO_PAUSE_EXECUTION(thd, 0.0002);
|
||||
je.killed_ptr= (uint32_t *) &thd->killed;
|
||||
|
||||
if (json_normalize(&je, &normalized_json,
|
||||
raw_json->ptr(), raw_json->length(),
|
||||
raw_json->charset()))
|
||||
if (json_normalize_engine(&je, &normalized_json,
|
||||
raw_json->ptr(), raw_json->length(),
|
||||
raw_json->charset()))
|
||||
goto null_return;
|
||||
|
||||
buf->length(0);
|
||||
@@ -4840,13 +4840,13 @@ int compare_nested_object(json_engine_t *js, json_engine_t *value)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
if (json_normalize(&je, &a_res, a.ptr(), a.length(), value->s.cs))
|
||||
if (json_normalize_engine(&je, &a_res, a.ptr(), a.length(), value->s.cs))
|
||||
{
|
||||
value->s.error= je.s.error;
|
||||
value->s.c_str= je.s.c_str;
|
||||
goto error;
|
||||
}
|
||||
if (json_normalize(&je, &b_res, b.ptr(), b.length(), value->s.cs))
|
||||
if (json_normalize_engine(&je, &b_res, b.ptr(), b.length(), value->s.cs))
|
||||
{
|
||||
js->s.error= je.s.error;
|
||||
js->s.c_str= je.s.c_str;
|
||||
|
||||
@@ -784,8 +784,8 @@ json_norm_build(json_engine_t *je, struct json_norm_value *root,
|
||||
|
||||
|
||||
int
|
||||
json_normalize(json_engine_t *je, DYNAMIC_STRING *result,
|
||||
const char *s, size_t size, CHARSET_INFO *cs)
|
||||
json_normalize_engine(json_engine_t *je, DYNAMIC_STRING *result,
|
||||
const char *s, size_t size, CHARSET_INFO *cs)
|
||||
{
|
||||
int err= 0;
|
||||
uint convert_err= 0;
|
||||
@@ -857,3 +857,12 @@ json_normalize_end:
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
json_normalize(DYNAMIC_STRING *result,
|
||||
const char *s, size_t size, CHARSET_INFO *cs)
|
||||
{
|
||||
json_engine_t je;
|
||||
|
||||
memset(&je, 0x00, sizeof(je));
|
||||
return json_normalize_engine(&je, result, s, size, cs);
|
||||
}
|
||||
|
||||
@@ -25,13 +25,12 @@ check_json_normalize(const char *in, const char *expected)
|
||||
{
|
||||
int err;
|
||||
DYNAMIC_STRING result;
|
||||
json_engine_t je= {0};
|
||||
|
||||
CHARSET_INFO *cs= &my_charset_utf8mb4_general_ci;
|
||||
|
||||
je.killed_ptr= NULL;
|
||||
init_dynamic_string(&result, NULL, 0, 0);
|
||||
|
||||
err= json_normalize(&je, &result, in, strlen(in), cs);
|
||||
err= json_normalize(&result, in, strlen(in), cs);
|
||||
|
||||
ok(err == 0, "normalize err?");
|
||||
|
||||
@@ -47,29 +46,26 @@ static void
|
||||
test_json_normalize_invalid(void)
|
||||
{
|
||||
DYNAMIC_STRING result;
|
||||
json_engine_t je= {0};
|
||||
|
||||
CHARSET_INFO *cs= &my_charset_utf8mb4_general_ci;
|
||||
|
||||
init_dynamic_string(&result, NULL, 0, 0);
|
||||
ok(json_normalize(&je, &result, STRING_WITH_LEN(""), cs) != 0,
|
||||
ok(json_normalize(&result, STRING_WITH_LEN(""), cs) != 0,
|
||||
"expected normalized error");
|
||||
dynstr_free(&result);
|
||||
|
||||
memset(&je, 0, sizeof(je));
|
||||
init_dynamic_string(&result, NULL, 0, 0);
|
||||
ok(json_normalize(&je, &result, STRING_WITH_LEN("["), cs) != 0,
|
||||
ok(json_normalize(&result, STRING_WITH_LEN("["), cs) != 0,
|
||||
"expected normalized error");
|
||||
dynstr_free(&result);
|
||||
|
||||
memset(&je, 0, sizeof(je));
|
||||
init_dynamic_string(&result, NULL, 0, 0);
|
||||
ok(json_normalize(&je, &result, STRING_WITH_LEN("}"), cs) != 0,
|
||||
ok(json_normalize(&result, STRING_WITH_LEN("}"), cs) != 0,
|
||||
"expected normalized error");
|
||||
dynstr_free(&result);
|
||||
|
||||
memset(&je, 0, sizeof(je));
|
||||
init_dynamic_string(&result, NULL, 0, 0);
|
||||
ok(json_normalize(&je, &result, NULL, 0, cs) != 0,
|
||||
ok(json_normalize(&result, NULL, 0, cs) != 0,
|
||||
"expected normalized error");
|
||||
dynstr_free(&result);
|
||||
}
|
||||
@@ -204,19 +200,17 @@ test_json_normalize_non_utf8(void)
|
||||
const char utf8[]= { 0x22, 0xC3, 0x8A, 0x22, 0x00 };
|
||||
const char latin[] = { 0x22, 0xCA, 0x22, 0x00 };
|
||||
DYNAMIC_STRING result;
|
||||
json_engine_t je= {0};
|
||||
CHARSET_INFO *cs_utf8= &my_charset_utf8mb4_bin;
|
||||
CHARSET_INFO *cs_latin= &my_charset_latin1;
|
||||
|
||||
init_dynamic_string(&result, NULL, 0, 0);
|
||||
err= json_normalize(&je, &result, utf8, strlen(utf8), cs_utf8);
|
||||
err= json_normalize(&result, utf8, strlen(utf8), cs_utf8);
|
||||
ok(err == 0, "normalize err?");
|
||||
ok((strcmp(utf8, result.str) == 0), "utf8 round trip");
|
||||
dynstr_free(&result);
|
||||
|
||||
memset(&je, 0, sizeof(je));
|
||||
init_dynamic_string(&result, NULL, 0, 0);
|
||||
err= json_normalize(&je, &result, latin, strlen(latin), cs_latin);
|
||||
err= json_normalize(&result, latin, strlen(latin), cs_latin);
|
||||
ok(err == 0, "normalize err?");
|
||||
ok((strcmp(utf8, result.str) == 0), "latin to utf8 round trip");
|
||||
dynstr_free(&result);
|
||||
|
||||
Reference in New Issue
Block a user