Skip to content

Commit 3bf585e

Browse files
committed
Web.JSON: Encode blob to list.
1 parent 0abbd05 commit 3bf585e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

autoload/vital/__vital__/Web/JSON.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ endfunction
9393
function! s:_vital_loaded(V) abort
9494
let s:V = a:V
9595
let s:string = s:V.import('Data.String')
96+
let s:bytes = s:V.import('Data.List.Byte')
9697
endfunction
9798

9899
function! s:_vital_depends() abort
@@ -197,6 +198,8 @@ function! s:_encode(val, settings) abort
197198
return val
198199
elseif t == 6 || t == 7
199200
return get(s:special_constants, a:val)
201+
elseif t == 10
202+
return s:_encode_list(s:bytes.from_blob(a:val), a:settings)
200203
else
201204
return string(a:val)
202205
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)