Skip to content

Commit 56ead34

Browse files
committed
patch 7.4.1238
Problem: Can't handle two messages right after each other. Solution: Find the end of the JSON. Read more when incomplete. Add a C test for the JSON decoding.
1 parent d9ea906 commit 56ead34

9 files changed

Lines changed: 533 additions & 138 deletions

File tree

src/Makefile

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,11 +1545,13 @@ EXTRA_SRC = hangulin.c if_lua.c if_mzsch.c auto/if_perl.c if_perlsfio.c \
15451545
$(GRESOURCE_SRC)
15461546

15471547
# Unittest files
1548+
JSON_TEST_SRC = json_test.c
1549+
JSON_TEST_TARGET = json_test$(EXEEXT)
15481550
MEMFILE_TEST_SRC = memfile_test.c
15491551
MEMFILE_TEST_TARGET = memfile_test$(EXEEXT)
15501552

1551-
UNITTEST_SRC = $(MEMFILE_TEST_SRC)
1552-
UNITTEST_TARGETS = $(MEMFILE_TEST_TARGET)
1553+
UNITTEST_SRC = $(JSON_TEST_SRC) $(MEMFILE_TEST_SRC)
1554+
UNITTEST_TARGETS = $(JSON_TEST_TARGET) $(MEMFILE_TEST_TARGET)
15531555

15541556
# All sources, also the ones that are not configured
15551557
ALL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(UNITTEST_SRC) $(EXTRA_SRC)
@@ -1588,7 +1590,6 @@ OBJ_COMMON = \
15881590
$(HANGULIN_OBJ) \
15891591
objects/if_cscope.o \
15901592
objects/if_xcmdsrv.o \
1591-
objects/json.o \
15921593
objects/mark.o \
15931594
objects/memline.o \
15941595
objects/menu.o \
@@ -1914,6 +1915,7 @@ types.vim: $(TAGS_SRC) $(TAGS_INCL)
19141915
ctags --c-kinds=gstu -o- $(TAGS_SRC) $(TAGS_INCL) |\
19151916
awk 'BEGIN{printf("syntax keyword Type\t")}\
19161917
{printf("%s ", $$1)}END{print ""}' > $@
1918+
echo "syn keyword Constant OK FAIL TRUE FALSE MAYBE" >> $@
19171919

19181920
# Execute the test scripts. Run these after compiling Vim, before installing.
19191921
# This doesn't depend on $(VIMTARGET), because that won't work when configure
@@ -1948,6 +1950,12 @@ unittest unittests: $(UNITTEST_TARGETS)
19481950
./$$t || exit 1; echo $$t passed; \
19491951
done
19501952

1953+
run_json_test: $(JSON_TEST_TARGET)
1954+
./$(JSON_TEST_TARGET)
1955+
1956+
run_memfile_test: $(MEMFILE_TEST_TARGET)
1957+
./$(MEMFILE_TEST_TARGET)
1958+
19511959
# Run individual OLD style test, assuming that Vim was already compiled.
19521960
test1 \
19531961
test_autocmd_option \
@@ -2040,6 +2048,13 @@ testclean:
20402048

20412049
# Unittests
20422050
# It's build just like Vim to satisfy all dependencies.
2051+
$(JSON_TEST_TARGET): auto/config.mk objects $(JSON_TEST_OBJ)
2052+
$(CCC) version.c -o objects/version.o
2053+
@LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
2054+
-o $(JSON_TEST_TARGET) $(JSON_TEST_OBJ) $(ALL_LIBS)" \
2055+
MAKE="$(MAKE)" LINK_AS_NEEDED=$(LINK_AS_NEEDED) \
2056+
sh $(srcdir)/link.sh
2057+
20432058
$(MEMFILE_TEST_TARGET): auto/config.mk objects $(MEMFILE_TEST_OBJ)
20442059
$(CCC) version.c -o objects/version.o
20452060
@LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
@@ -2811,6 +2826,9 @@ objects/integration.o: integration.c
28112826
objects/json.o: json.c
28122827
$(CCC) -o $@ json.c
28132828

2829+
objects/json_test.o: json_test.c
2830+
$(CCC) -o $@ json_test.c
2831+
28142832
objects/main.o: main.c
28152833
$(CCC) -o $@ main.c
28162834

@@ -3301,6 +3319,10 @@ objects/gui_at_fs.o: gui_at_fs.c vim.h auto/config.h feature.h os_unix.h \
33013319
objects/pty.o: pty.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h ascii.h \
33023320
keymap.h term.h macros.h option.h structs.h regexp.h gui.h gui_beval.h \
33033321
proto/gui_beval.pro alloc.h ex_cmds.h proto.h globals.h farsi.h arabic.h
3322+
objects/json_test.o: json_test.c main.c vim.h auto/config.h feature.h os_unix.h \
3323+
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
3324+
regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h ex_cmds.h proto.h \
3325+
globals.h farsi.h arabic.h farsi.c arabic.c json.c
33043326
objects/memfile_test.o: memfile_test.c main.c vim.h auto/config.h feature.h \
33053327
os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h \
33063328
structs.h regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h \

src/channel.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,8 @@ channel_read_json(int ch_idx)
540540
/* TODO: make reader work properly */
541541
/* reader.js_buf = channel_peek(ch_idx); */
542542
reader.js_buf = channel_get_all(ch_idx);
543-
reader.js_eof = TRUE;
544-
/* reader.js_eof = FALSE; */
545543
reader.js_used = 0;
544+
reader.js_fill = NULL;
546545
/* reader.js_fill = channel_fill; */
547546
reader.js_cookie = &ch_idx;
548547
if (json_decode(&reader, &listtv) == OK)

src/eval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14100,9 +14100,9 @@ f_jsondecode(typval_T *argvars, typval_T *rettv)
1410014100
js_read_T reader;
1410114101

1410214102
reader.js_buf = get_tv_string(&argvars[0]);
14103-
reader.js_eof = TRUE;
14103+
reader.js_fill = NULL;
1410414104
reader.js_used = 0;
14105-
if (json_decode(&reader, rettv) == FAIL)
14105+
if (json_decode_all(&reader, rettv) != OK)
1410614106
EMSG(_(e_invarg));
1410714107
}
1410814108

0 commit comments

Comments
 (0)