diff options
author | ZyX <kp-pav@yandex.ru> | 2017-01-04 15:06:33 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-01-04 15:06:33 +0300 |
commit | 24b3b938e888bd053aaa1265266a5b0deaa3a0a6 (patch) | |
tree | b952def68b5f1d0a3ce39a1b455dd2e4ee541e44 | |
parent | d82f5d1ba2f870ea6a29019993b3818e550338b7 (diff) | |
download | rneovim-24b3b938e888bd053aaa1265266a5b0deaa3a0a6.tar.gz rneovim-24b3b938e888bd053aaa1265266a5b0deaa3a0a6.tar.bz2 rneovim-24b3b938e888bd053aaa1265266a5b0deaa3a0a6.zip |
plugin/shada: Handle NUL characters with intchar correctly
Fixes #5482
-rw-r--r-- | runtime/autoload/shada.vim | 13 | ||||
-rw-r--r-- | test/functional/plugin/shada_spec.lua | 37 |
2 files changed, 38 insertions, 12 deletions
diff --git a/runtime/autoload/shada.vim b/runtime/autoload/shada.vim index 9be85b6f2e..cf27ee608a 100644 --- a/runtime/autoload/shada.vim +++ b/runtime/autoload/shada.vim @@ -241,8 +241,6 @@ function s:shada_check_type(type, val) abort if msg isnot# 0 return msg endif - if a:val > 0 || a:val < 1 - endif return 0 elseif a:type is# 'binarray' if type isnot# 'array' @@ -359,9 +357,14 @@ function s:shada_string(type, v) abort if (has_key(s:SHADA_ENUMS, a:type) && type(a:v) == type(0) \&& has_key(s:SHADA_REV_ENUMS[a:type], a:v)) return s:SHADA_REV_ENUMS[a:type][a:v] - elseif (a:type is# 'intchar' && type(a:v) == type(0) - \&& strtrans(nr2char(a:v)) is# nr2char(a:v)) - return "'" . nr2char(a:v) . "'" + " Restricting a:v to be <= 127 is not necessary, but intchar constants are + " normally expected to be either ASCII printable characters or NUL. + elseif a:type is# 'intchar' && type(a:v) == type(0) && a:v >= 0 && a:v <= 127 + if a:v > 0 && strtrans(nr2char(a:v)) is# nr2char(a:v) + return "'" . nr2char(a:v) . "'" + else + return "'\\" . a:v . "'" + endif else return msgpack#string(a:v) endif diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index b1209a22e9..b543037ae2 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -609,6 +609,18 @@ describe('In autoload/shada.vim', function() 'abc', -1, ]}] ]]):gsub('\n', '')) + -- Regression: NUL separator must be properly supported + sd2strings_eq({ + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type SEARCH', + ' - contents ""', + ' - separator \'\\0\'', + }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + 1, + '', + 0x0 + ]}] ]]):gsub('\n', '')) end) it('works with register items', function() @@ -837,7 +849,7 @@ describe('In autoload/shada.vim', function() sd2strings_eq({ 'Global mark with timestamp ' .. epoch .. ':', ' % Key Description Value', - ' + n name 20', + ' + n name \'\\20\'', ' + f file name "foo"', ' # Value is negative', ' + l line number -10', @@ -852,7 +864,18 @@ describe('In autoload/shada.vim', function() sd2strings_eq({ 'Global mark with timestamp ' .. epoch .. ':', ' % Key Description Value', - ' + n name 20', + ' + n name 128', + ' + f file name "foo"', + ' + l line number 1', + ' + c column 0', + }, ([[ [{'type': 7, 'timestamp': 0, 'data': { + 'n': 128, + 'f': 'foo', + }}] ]]):gsub('\n', '')) + sd2strings_eq({ + 'Global mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' + n name \'\\20\'', ' + f file name "foo"', ' # Expected integer', ' + l line number "FOO"', @@ -1123,7 +1146,7 @@ describe('In autoload/shada.vim', function() 'Local mark with timestamp ' .. epoch .. ':', ' % Key Description Value', ' + f file name "foo"', - ' + n name 20', + ' + n name \'\\20\'', ' # Value is negative', ' + l line number -10', ' # Value is negative', @@ -1138,7 +1161,7 @@ describe('In autoload/shada.vim', function() 'Local mark with timestamp ' .. epoch .. ':', ' % Key Description Value', ' + f file name "foo"', - ' + n name 20', + ' + n name \'\\20\'', ' # Expected integer', ' + l line number "FOO"', ' # Expected integer', @@ -1932,13 +1955,13 @@ describe('In autoload/shada.vim', function() 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', ' # Expected binary string', - ' + f file name 10', + ' + f file name \'\\10\'', ' + l line number 1', ' + c column 0', '', ' % Key Description Value', ' # Expected binary string', - ' + f file name 20', + ' + f file name \'\\20\'', ' + l line number 1', ' + c column 0', }) @@ -1948,7 +1971,7 @@ describe('In autoload/shada.vim', function() 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', ' # Expected binary string', - ' + f file name 10', + ' + f file name \'\\10\'', ' + l line number 1', ' + c column 0', '', |