aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-03-12 13:47:34 +0300
committerZyX <kp-pav@yandex.ru>2016-04-18 02:48:20 +0300
commitc129f6cfafc77d3f6e22b2ac11b5c8f2cec033d3 (patch)
treeb40e1c23690bf9ddffff8722d2b7019247bdd41a
parentd06c2a1b1846a96a45625ad5472a235b2d249933 (diff)
downloadrneovim-c129f6cfafc77d3f6e22b2ac11b5c8f2cec033d3.tar.gz
rneovim-c129f6cfafc77d3f6e22b2ac11b5c8f2cec033d3.tar.bz2
rneovim-c129f6cfafc77d3f6e22b2ac11b5c8f2cec033d3.zip
eval/decode: Accept `\r` as space character
-rw-r--r--src/nvim/eval/decode.c8
-rw-r--r--test/functional/eval/json_functions_spec.lua6
2 files changed, 11 insertions, 3 deletions
diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c
index 2e9bf8fbac..10dd36c137 100644
--- a/src/nvim/eval/decode.c
+++ b/src/nvim/eval/decode.c
@@ -617,7 +617,7 @@ int json_decode_string(const char *const buf, const size_t buf_len,
{
const char *p = buf;
const char *const e = buf + buf_len;
- while (p < e && (*p == ' ' || *p == '\t' || *p == '\n')) {
+ while (p < e && (*p == ' ' || *p == TAB || *p == NL || *p == CAR)) {
p++;
}
if (p == e) {
@@ -730,7 +730,8 @@ json_decode_string_cycle_start:
}
case ' ':
case TAB:
- case NL: {
+ case NL:
+ case CAR: {
continue;
}
case 'n': {
@@ -870,7 +871,8 @@ json_decode_string_after_cycle:
switch (*p) {
case NL:
case ' ':
- case TAB: {
+ case TAB:
+ case CAR: {
break;
}
default: {
diff --git a/test/functional/eval/json_functions_spec.lua b/test/functional/eval/json_functions_spec.lua
index 8438620109..8483152dbf 100644
--- a/test/functional/eval/json_functions_spec.lua
+++ b/test/functional/eval/json_functions_spec.lua
@@ -515,6 +515,12 @@ describe('json_decode() function', function()
eq('Vim(call):E474: Attempt to decode a blank string',
exc_exec('call json_decode(" \\t\\n \\n\\t\\t \\n\\t\\n \\n \\t\\n\\t ")'))
end)
+
+ it('accepts all spaces in every position where space may be put', function()
+ local s = ' \t\n\r \t\r\n \n\t\r \n\r\t \r\t\n \r\n\t\t \n\r\t \r\n\t\n \r\t\n\r \t\r \n\t\r\n \n \t\r\n \r\t\n\t \r\n\t\r \n\r \t\n\r\t \r \t\n\r \n\t\r\t \n\r\t\n \r\n \t\r\n\t'
+ local str = ('%s{%s"key"%s:%s[%s"val"%s,%s"val2"%s]%s,%s"key2"%s:%s1%s}%s'):gsub('%%s', s)
+ eq({key={'val', 'val2'}, key2=1}, funcs.json_decode(str))
+ end)
end)
describe('json_encode() function', function()