mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(typval)!: remove distinction of binary and nonbinary strings
This is a breaking change which will make refactor of typval and shada code a lot easier. In particular, code that would use or check for v:msgpack_types.binary in the wild would be broken. This appears to be rarely used in existing plugins. Also some cases where v:msgpack_type.string would be used to represent a binary string of "string" type, we use a BLOB instead, which is vimscripts native type for binary blobs, and already was used for BIN formats when necessary. msgpackdump(msgpackparse(data)) no longer preserves the distinction of BIN and STR strings. This is very common behavior for language-specific msgpack bindings. Nvim uses msgpack as a tool to serialize its data. Nvim is not a tool to bit-perfectly manipulate arbitrary msgpack data out in the wild. The changed tests should indicate how behavior changes in various edge cases.
This commit is contained in:
@@ -361,7 +361,7 @@ endfunction
|
||||
let s:MSGPACK_STANDARD_TYPES = {
|
||||
\type(0): 'integer',
|
||||
\type(0.0): 'float',
|
||||
\type(''): 'binary',
|
||||
\type(''): 'string',
|
||||
\type([]): 'array',
|
||||
\type({}): 'map',
|
||||
\type(v:true): 'boolean',
|
||||
@@ -412,9 +412,15 @@ endfunction
|
||||
""
|
||||
" Dump |msgpack-special-dict| that represents a string. If any additional
|
||||
" parameter is given then it dumps binary string.
|
||||
function s:msgpack_dump_string(v, ...) abort
|
||||
let ret = [a:0 ? '"' : '="']
|
||||
for v in a:v._VAL
|
||||
function s:msgpack_dump_string(v) abort
|
||||
if type(a:v) == type({})
|
||||
let val = a:v
|
||||
else
|
||||
let val = {'_VAL': split(a:v, "\n", 1)}
|
||||
end
|
||||
|
||||
let ret = ['"']
|
||||
for v in val._VAL
|
||||
call add(
|
||||
\ret,
|
||||
\substitute(
|
||||
@@ -426,16 +432,6 @@ function s:msgpack_dump_string(v, ...) abort
|
||||
return join(ret, '')
|
||||
endfunction
|
||||
|
||||
""
|
||||
" Dump binary string.
|
||||
function s:msgpack_dump_binary(v) abort
|
||||
if type(a:v) == type({})
|
||||
return s:msgpack_dump_string(a:v, 1)
|
||||
else
|
||||
return s:msgpack_dump_string({'_VAL': split(a:v, "\n", 1)}, 1)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
""
|
||||
" Dump array value.
|
||||
function s:msgpack_dump_array(v) abort
|
||||
@@ -449,7 +445,7 @@ function s:msgpack_dump_map(v) abort
|
||||
let ret = ['{']
|
||||
if msgpack#special_type(a:v) is 0
|
||||
for [k, v] in items(a:v)
|
||||
let ret += [s:msgpack_dump_string({'_VAL': split(k, "\n", 1)}),
|
||||
let ret += [s:msgpack_dump_string({'_VAL': split(k, "\n")}),
|
||||
\': ',
|
||||
\msgpack#string(v),
|
||||
\', ']
|
||||
@@ -479,7 +475,7 @@ endfunction
|
||||
" Dump extension value.
|
||||
function s:msgpack_dump_ext(v) abort
|
||||
return printf('+(%i)%s', a:v._VAL[0],
|
||||
\s:msgpack_dump_string({'_VAL': a:v._VAL[1]}, 1))
|
||||
\s:msgpack_dump_string({'_VAL': a:v._VAL[1]}))
|
||||
endfunction
|
||||
|
||||
""
|
||||
@@ -619,9 +615,7 @@ function msgpack#eval(s, special_objs) abort
|
||||
throw '"-invalid:Invalid string: ' . s
|
||||
endif
|
||||
call add(expr, '{''_TYPE'': v:msgpack_types.')
|
||||
if empty(match[1])
|
||||
call add(expr, 'binary')
|
||||
elseif match[1] is# '='
|
||||
if empty(match[1]) || match[1] is# '='
|
||||
call add(expr, 'string')
|
||||
else
|
||||
call add(expr, 'ext')
|
||||
@@ -772,7 +766,7 @@ function msgpack#equal(a, b)
|
||||
let a = aspecial is 0 ? a:a : a:a._VAL
|
||||
let b = bspecial is 0 ? a:b : a:b._VAL
|
||||
return msgpack#equal(a, b)
|
||||
elseif atype is# 'binary'
|
||||
elseif atype is# 'string'
|
||||
let a = (aspecial is 0 ? split(a:a, "\n", 1) : a:a._VAL)
|
||||
let b = (bspecial is 0 ? split(a:b, "\n", 1) : a:b._VAL)
|
||||
return a ==# b
|
||||
@@ -787,13 +781,17 @@ function msgpack#equal(a, b)
|
||||
" Non-special mapping cannot have non-string keys
|
||||
return 0
|
||||
endif
|
||||
if (empty(k._VAL)
|
||||
\|| k._VAL ==# [""]
|
||||
\|| !empty(filter(copy(k._VAL), 'stridx(v:val, "\n") != -1')))
|
||||
" Non-special mapping cannot have zero byte in key or an empty key
|
||||
return 0
|
||||
if type(k) == type({})
|
||||
if (empty(k._VAL)
|
||||
\|| k._VAL ==# [""]
|
||||
\|| !empty(filter(copy(k._VAL), 'stridx(v:val, "\n") != -1')))
|
||||
" Non-special mapping cannot have zero byte in key or an empty key
|
||||
return 0
|
||||
endif
|
||||
let kstr = join(k._VAL, "\n")
|
||||
else
|
||||
let kstr = k
|
||||
endif
|
||||
let kstr = join(k._VAL, "\n")
|
||||
if !has_key(akeys, kstr)
|
||||
" Protects from both missing and duplicate keys
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user