Skip to content

Commit c7eec04

Browse files
committed
fix json_encode with funcref values for null/true/false
1 parent 3448c39 commit c7eec04

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

autoload/webapi/json.vim

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,26 @@ function! webapi#json#decode(json) abort
2525
return json_decode(a:json)
2626
endfunction
2727

28+
function! s:convert_funcrefs(val) abort
29+
if type(a:val) == 2
30+
let s = string(a:val)
31+
if s == "function('webapi#json#null')"
32+
return v:null
33+
elseif s == "function('webapi#json#true')"
34+
return v:true
35+
elseif s == "function('webapi#json#false')"
36+
return v:false
37+
endif
38+
elseif type(a:val) == 3
39+
return map(copy(a:val), 's:convert_funcrefs(v:val)')
40+
elseif type(a:val) == 4
41+
return map(copy(a:val), 's:convert_funcrefs(v:val)')
42+
endif
43+
return a:val
44+
endfunction
45+
2846
function! webapi#json#encode(val) abort
29-
return json_encode(a:val)
47+
return json_encode(s:convert_funcrefs(a:val))
3048
endfunction
3149

3250
else

0 commit comments

Comments
 (0)