Skip to content

Commit 70d99ca

Browse files
committed
Web.JSON: Throws exception when encode funcref, job or channel.
1 parent ddd9525 commit 70d99ca

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

autoload/vital/__vital__/Web/JSON.vim

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ function! s:_encode(val, settings) abort
180180
return 'false'
181181
elseif s:const.null == a:val
182182
return 'null'
183-
else
184-
" backward compatibility
185-
return string(a:val)
186183
endif
187184
elseif t == 3
188185
return s:_encode_list(a:val, a:settings)
@@ -200,9 +197,8 @@ function! s:_encode(val, settings) abort
200197
return get(s:special_constants, a:val)
201198
elseif t == 10
202199
return s:_encode_list(s:bytes.from_blob(a:val), a:settings)
203-
else
204-
return string(a:val)
205200
endif
201+
throw 'vital: Web.JSON: Invalid argument: ' . string(a:val)
206202
endfunction
207203

208204
" @vimlint(EVL102, 1, l:ns)

test/Web/JSON.vimspec

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,5 +308,26 @@ Describe Web.JSON
308308
Assert Equals(JSON.encode(0z), '[]')
309309
Assert Equals(JSON.encode(0zFF.00.ED.01.5D.AF), '[255,0,237,1,93,175]')
310310
End
311+
312+
It throws exception when encodes funcref
313+
let Funcref = function('get')
314+
Throws /^vital: Web\.JSON: Invalid argument: / JSON.encode(Funcref)
315+
End
316+
317+
It throws exception when encodes job
318+
if !exists('*test_null_job')
319+
Skip no available job type.
320+
endif
321+
let job = test_null_job()
322+
Throws /^vital: Web\.JSON: Invalid argument: / JSON.encode(job)
323+
End
324+
325+
It throws exception when encodes channel
326+
if !exists('*test_null_channel')
327+
Skip no available channel type.
328+
endif
329+
let ch = test_null_channel()
330+
Throws /^vital: Web\.JSON: Invalid argument: / JSON.encode(ch)
331+
End
311332
End
312333
End

0 commit comments

Comments
 (0)