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:
ZyX
2016-02-11 01:29:09 +03:00
parent 77776b09c6
commit f0bd4a1494
3 changed files with 38 additions and 11 deletions

View File

@@ -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)