forked from aniani/vim
patch 8.2.0800: errors from failing test are unclear
Problem: Errors from failing test are unclear. Solution: Include text where parsing failed.
This commit is contained in:
20
src/json.c
20
src/json.c
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
static int json_encode_item(garray_T *gap, typval_T *val, int copyID, int options);
|
static int json_encode_item(garray_T *gap, typval_T *val, int copyID, int options);
|
||||||
|
|
||||||
|
static char e_json_error[] = N_("E491: json decode error at '%s'");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Encode "val" into a JSON format string.
|
* Encode "val" into a JSON format string.
|
||||||
* The result is added to "gap"
|
* The result is added to "gap"
|
||||||
@@ -740,7 +742,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
|
|||||||
retval = json_decode_string(reader, cur_item, *p);
|
retval = json_decode_string(reader, cur_item, *p);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emsg(_(e_invarg));
|
semsg(_(e_json_error), p);
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -748,7 +750,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
|
|||||||
case ',': // comma: empty item
|
case ',': // comma: empty item
|
||||||
if ((options & JSON_JS) == 0)
|
if ((options & JSON_JS) == 0)
|
||||||
{
|
{
|
||||||
emsg(_(e_invarg));
|
semsg(_(e_json_error), p);
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -778,7 +780,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
|
|||||||
}
|
}
|
||||||
if (!VIM_ISDIGIT(*sp))
|
if (!VIM_ISDIGIT(*sp))
|
||||||
{
|
{
|
||||||
emsg(_(e_invarg));
|
semsg(_(e_json_error), p);
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -809,7 +811,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
|
|||||||
&nr, NULL, 0, TRUE);
|
&nr, NULL, 0, TRUE);
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
{
|
{
|
||||||
emsg(_(e_invarg));
|
semsg(_(e_json_error), p);
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
@@ -962,7 +964,7 @@ item_end:
|
|||||||
retval = MAYBE;
|
retval = MAYBE;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emsg(_(e_invarg));
|
semsg(_(e_json_error), p);
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
}
|
}
|
||||||
goto theend;
|
goto theend;
|
||||||
@@ -980,7 +982,7 @@ item_end:
|
|||||||
retval = MAYBE;
|
retval = MAYBE;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emsg(_(e_invarg));
|
semsg(_(e_json_error), p);
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
}
|
}
|
||||||
goto theend;
|
goto theend;
|
||||||
@@ -1036,7 +1038,7 @@ item_end:
|
|||||||
retval = MAYBE;
|
retval = MAYBE;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emsg(_(e_invarg));
|
semsg(_(e_json_error), p);
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
}
|
}
|
||||||
goto theend;
|
goto theend;
|
||||||
@@ -1055,7 +1057,7 @@ item_end:
|
|||||||
res->v_type = VAR_SPECIAL;
|
res->v_type = VAR_SPECIAL;
|
||||||
res->vval.v_number = VVAL_NONE;
|
res->vval.v_number = VVAL_NONE;
|
||||||
}
|
}
|
||||||
emsg(_(e_invarg));
|
semsg(_(e_json_error), p);
|
||||||
|
|
||||||
theend:
|
theend:
|
||||||
ga_clear(&stack);
|
ga_clear(&stack);
|
||||||
@@ -1079,7 +1081,7 @@ json_decode_all(js_read_T *reader, typval_T *res, int options)
|
|||||||
if (ret != OK)
|
if (ret != OK)
|
||||||
{
|
{
|
||||||
if (ret == MAYBE)
|
if (ret == MAYBE)
|
||||||
emsg(_(e_invarg));
|
semsg(_(e_json_error), reader->js_buf);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
json_skip_white(reader);
|
json_skip_white(reader);
|
||||||
|
@@ -148,36 +148,36 @@ func Test_json_decode()
|
|||||||
call assert_fails("call json_decode('{\"\": \"ok\", \"\": \"bad\"}')", 'E938:')
|
call assert_fails("call json_decode('{\"\": \"ok\", \"\": \"bad\"}')", 'E938:')
|
||||||
|
|
||||||
call assert_equal({'n': 1}, json_decode('{"n":1,}'))
|
call assert_equal({'n': 1}, json_decode('{"n":1,}'))
|
||||||
call assert_fails("call json_decode(\"{'n':'1',}\")", 'E474:')
|
call assert_fails("call json_decode(\"{'n':'1',}\")", 'E491:')
|
||||||
call assert_fails("call json_decode(\"'n'\")", 'E474:')
|
call assert_fails("call json_decode(\"'n'\")", 'E491:')
|
||||||
|
|
||||||
call assert_fails('call json_decode("\"")', "E474:")
|
call assert_fails('call json_decode("\"")', "E491:")
|
||||||
call assert_fails('call json_decode("blah")', "E474:")
|
call assert_fails('call json_decode("blah")', "E491:")
|
||||||
call assert_fails('call json_decode("true blah")', "E488:")
|
call assert_fails('call json_decode("true blah")', "E488:")
|
||||||
call assert_fails('call json_decode("<foobar>")', "E474:")
|
call assert_fails('call json_decode("<foobar>")', "E491:")
|
||||||
call assert_fails('call json_decode("{\"a\":1,\"a\":2}")', "E938:")
|
call assert_fails('call json_decode("{\"a\":1,\"a\":2}")', "E938:")
|
||||||
|
|
||||||
call assert_fails('call json_decode("{")', "E474:")
|
call assert_fails('call json_decode("{")', "E491:")
|
||||||
call assert_fails('call json_decode("{foobar}")', "E474:")
|
call assert_fails('call json_decode("{foobar}")', "E491:")
|
||||||
call assert_fails('call json_decode("{\"n\",")', "E474:")
|
call assert_fails('call json_decode("{\"n\",")', "E491:")
|
||||||
call assert_fails('call json_decode("{\"n\":")', "E474:")
|
call assert_fails('call json_decode("{\"n\":")', "E491:")
|
||||||
call assert_fails('call json_decode("{\"n\":1")', "E474:")
|
call assert_fails('call json_decode("{\"n\":1")', "E491:")
|
||||||
call assert_fails('call json_decode("{\"n\":1,")', "E474:")
|
call assert_fails('call json_decode("{\"n\":1,")', "E491:")
|
||||||
call assert_fails('call json_decode("{\"n\",1}")', "E474:")
|
call assert_fails('call json_decode("{\"n\",1}")', "E491:")
|
||||||
call assert_fails('call json_decode("{-}")', "E474:")
|
call assert_fails('call json_decode("{-}")', "E491:")
|
||||||
|
|
||||||
call assert_fails('call json_decode("[foobar]")', "E474:")
|
call assert_fails('call json_decode("[foobar]")', "E491:")
|
||||||
call assert_fails('call json_decode("[")', "E474:")
|
call assert_fails('call json_decode("[")', "E491:")
|
||||||
call assert_fails('call json_decode("[1")', "E474:")
|
call assert_fails('call json_decode("[1")', "E491:")
|
||||||
call assert_fails('call json_decode("[1,")', "E474:")
|
call assert_fails('call json_decode("[1,")', "E491:")
|
||||||
call assert_fails('call json_decode("[1 2]")', "E474:")
|
call assert_fails('call json_decode("[1 2]")', "E491:")
|
||||||
|
|
||||||
call assert_fails('call json_decode("[1,,2]")', "E474:")
|
call assert_fails('call json_decode("[1,,2]")', "E491:")
|
||||||
|
|
||||||
call assert_fails('call json_decode("{{}:42}")', "E474:")
|
call assert_fails('call json_decode("{{}:42}")', "E491:")
|
||||||
call assert_fails('call json_decode("{[]:42}")', "E474:")
|
call assert_fails('call json_decode("{[]:42}")', "E491:")
|
||||||
|
|
||||||
call assert_fails('call json_decode("\"\\u111Z\"")', 'E474:')
|
call assert_fails('call json_decode("\"\\u111Z\"")', 'E491:')
|
||||||
call assert_equal('[😂]', json_decode('"[\uD83D\uDE02]"'))
|
call assert_equal('[😂]', json_decode('"[\uD83D\uDE02]"'))
|
||||||
call assert_equal('a😂b', json_decode('"a\uD83D\uDE02b"'))
|
call assert_equal('a😂b', json_decode('"a\uD83D\uDE02b"'))
|
||||||
endfunc
|
endfunc
|
||||||
|
@@ -746,6 +746,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
800,
|
||||||
/**/
|
/**/
|
||||||
799,
|
799,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user