mirror of
https://github.com/neovim/neovim.git
synced 2025-11-16 07:11:20 +00:00
eval/encode: Fix invalid UTF-8 strings handling:
1. Do not allow reading past buffer end when creating error messages. 2. Fix surrogate pairs range, avoid magic constants.
This commit is contained in:
@@ -663,4 +663,11 @@ describe('jsonencode() function', function()
|
||||
eq(1, eval('"\x01" =~# "\\\\p"'))
|
||||
eq('"\\u0001"', funcs.jsonencode('\x01'))
|
||||
end)
|
||||
|
||||
it('fails when using surrogate character in a UTF-8 string', function()
|
||||
eq('Vim(call):E474: UTF-8 string contains code point which belongs to a surrogate pair: \xED\xA0\x80',
|
||||
exc_exec('call jsonencode("\xED\xA0\x80")'))
|
||||
eq('Vim(call):E474: UTF-8 string contains code point which belongs to a surrogate pair: \xED\xAF\xBF',
|
||||
exc_exec('call jsonencode("\xED\xAF\xBF")'))
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user