Skip to content

Commit 04349a9

Browse files
committed
Web.JSON: Encode blob to list.
1 parent 416240d commit 04349a9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

autoload/vital/__vital__/Web/JSON.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ endfunction
9696
function! s:_vital_loaded(V) abort
9797
let s:V = a:V
9898
let s:string = s:V.import('Data.String')
99+
let s:bytes = s:V.import('Data.List.Byte')
99100
endfunction
100101

101102
function! s:_vital_depends() abort
102-
return ['Data.String']
103+
return ['Data.String', 'Data.List.Byte']
103104
endfunction
104105

105106
" @vimlint(EVL102, 1, l:null)
@@ -200,6 +201,8 @@ function! s:_encode(val, settings) abort
200201
return val
201202
elseif t == 6 || t == 7
202203
return get(s:special_constants, a:val)
204+
elseif t == 10
205+
return s:_encode_list(s:bytes.from_blob(a:val), a:settings)
203206
else
204207
return string(a:val)
205208
endif

test/Web/JSON.vimspec

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,13 @@ Describe Web.JSON
300300
Throws /^vital: Web.JSON:/ JSON.encode(1.0/0, s)
301301
Throws /^vital: Web.JSON:/ JSON.encode(-1.0/0, s)
302302
End
303+
304+
It encodes blob
305+
if !has('patch-8.1.0735')
306+
Skip no available blob type.
307+
endif
308+
Assert Equals(JSON.encode(0z), '[]')
309+
Assert Equals(JSON.encode(0zFF.00.ED.01.5D.AF), '[255,0,237,1,93,175]')
310+
End
303311
End
304312
End

0 commit comments

Comments
 (0)