Skip to content

Commit 059b748

Browse files
committed
patch 8.0.0309: cannot use an empty key in json
Problem: Cannot use an empty key in json. Solution: Allow for using an empty key.
1 parent 2f9e575 commit 059b748

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
863863
&& cur_item != NULL)
864864
{
865865
top_item->jd_key = get_tv_string_buf_chk(cur_item, key_buf);
866-
if (top_item->jd_key == NULL || *top_item->jd_key == NUL)
866+
if (top_item->jd_key == NULL)
867867
{
868868
clear_tv(cur_item);
869869
EMSG(_(e_invarg));

src/testdir/test_json.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ func Test_json_decode()
144144
call assert_equal(type(v:none), type(json_decode('')))
145145
call assert_equal("", json_decode('""'))
146146

147+
" empty key is OK
148+
call assert_equal({'': 'ok'}, json_decode('{"": "ok"}'))
149+
" but not twice
150+
call assert_fails("call json_decode('{\"\": \"ok\", \"\": \"bad\"}')", 'E938:')
151+
147152
call assert_equal({'n': 1}, json_decode('{"n":1,}'))
148153
call assert_fails("call json_decode(\"{'n':'1',}\")", 'E474:')
149154
call assert_fails("call json_decode(\"'n'\")", 'E474:')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
309,
767769
/**/
768770
308,
769771
/**/

0 commit comments

Comments
 (0)