patch 7.4.1278
Problem: When jsonencode() fails it still returns something.
Solution: Return an empty string on failure.
diff --git a/src/testdir/test_channel.py b/src/testdir/test_channel.py
index d8830c5..40a2043 100644
--- a/src/testdir/test_channel.py
+++ b/src/testdir/test_channel.py
@@ -93,6 +93,13 @@
print("sending: {}".format(cmd))
self.request.sendall(cmd.encode('utf-8'))
response = "ok"
+ elif decoded[1] == 'eval-error':
+ # Send an eval request that works but the result can't
+ # be encoded.
+ cmd = '["eval","function(\\"tr\\")", -3]'
+ print("sending: {}".format(cmd))
+ self.request.sendall(cmd.encode('utf-8'))
+ response = "ok"
elif decoded[1] == 'eval-bad':
# Send an eval request missing the third argument.
cmd = '["eval","xxx"]'
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim
index 94ad81c..2a56c0d 100644
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -118,10 +118,15 @@
sleep 10m
call assert_equal([-2, 'ERROR'], ch_sendexpr(handle, 'eval-result'))
+ " Send an eval request that works but can't be encoded.
+ call assert_equal('ok', ch_sendexpr(handle, 'eval-error'))
+ sleep 10m
+ call assert_equal([-3, 'ERROR'], ch_sendexpr(handle, 'eval-result'))
+
" Send a bad eval request. There will be no response.
call assert_equal('ok', ch_sendexpr(handle, 'eval-bad'))
sleep 10m
- call assert_equal([-2, 'ERROR'], ch_sendexpr(handle, 'eval-result'))
+ call assert_equal([-3, 'ERROR'], ch_sendexpr(handle, 'eval-result'))
" Send an expr request
call assert_equal('ok', ch_sendexpr(handle, 'an expr'))
diff --git a/src/testdir/test_json.vim b/src/testdir/test_json.vim
index 05c3949..52cffc8 100644
--- a/src/testdir/test_json.vim
+++ b/src/testdir/test_json.vim
@@ -75,6 +75,9 @@
call assert_fails('echo jsonencode(function("tr"))', 'E474:')
call assert_fails('echo jsonencode([function("tr")])', 'E474:')
call assert_fails('echo jsonencode({"key":v:none})', 'E474:')
+
+ silent! let res = jsonencode(function("tr"))
+ call assert_equal("", res)
endfunc
func Test_decode()