From f0bd4a149408e75ebf887530964e0948518938dc Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 11 Feb 2016 01:29:09 +0300 Subject: 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. --- test/functional/eval/json_functions_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/functional/eval/json_functions_spec.lua b/test/functional/eval/json_functions_spec.lua index 13597eb7a0..398fab6c4b 100644 --- a/test/functional/eval/json_functions_spec.lua +++ b/test/functional/eval/json_functions_spec.lua @@ -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) -- cgit