From 88989cc381c764978f7d7c8e387f3efc21333b4b Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Mon, 6 Feb 2017 21:56:09 +0100 Subject: patch 8.0.0312: failure when a channel receives a split json message Problem: When a json message arrives in pieces, the start is dropped and the decoding fails. Solution: Do not drop the start when it is still needed. (Kay Zheng) Add a test. Reset the timeout when something is received. --- src/testdir/test_channel.vim | 12 +++++++++++- src/testdir/test_channel_pipe.py | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/testdir') diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim index 81de17c34..28793b576 100644 --- a/src/testdir/test_channel.vim +++ b/src/testdir/test_channel.vim @@ -1141,7 +1141,11 @@ func Test_out_cb() let dict = {'thisis': 'dict: '} func dict.outHandler(chan, msg) dict - let g:Ch_outmsg = self.thisis . a:msg + if type(a:msg) == v:t_string + let g:Ch_outmsg = self.thisis . a:msg + else + let g:Ch_outobj = a:msg + endif endfunc func dict.errHandler(chan, msg) dict let g:Ch_errmsg = self.thisis . a:msg @@ -1161,6 +1165,12 @@ func Test_out_cb() call assert_equal("dict: hello", g:Ch_outmsg) call WaitFor('g:Ch_errmsg != ""') call assert_equal("dict: there", g:Ch_errmsg) + + " Receive a json object split in pieces + unlet! g:Ch_outobj + call ch_sendraw(job, "echosplit [0, {\"one\": 1,| \"tw|o\": 2, \"three\": 3|}]\n") + call WaitFor('exists("g:Ch_outobj")') + call assert_equal({'one': 1, 'two': 2, 'three': 3}, g:Ch_outobj) finally call job_stop(job) endtry diff --git a/src/testdir/test_channel_pipe.py b/src/testdir/test_channel_pipe.py index 639cc6c26..a67a81a85 100644 --- a/src/testdir/test_channel_pipe.py +++ b/src/testdir/test_channel_pipe.py @@ -29,6 +29,11 @@ if __name__ == "__main__": if typed.startswith("echo "): print(typed[5:-1]) sys.stdout.flush() + if typed.startswith("echosplit "): + for part in typed[10:-1].split('|'): + sys.stdout.write(part) + sys.stdout.flush() + time.sleep(0.05) if typed.startswith("double "): print(typed[7:-1] + "\nAND " + typed[7:-1]) sys.stdout.flush() -- cgit v1.2.3