diff options
author | ZyX <kp-pav@yandex.ru> | 2016-02-25 17:27:23 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2016-04-18 02:48:20 +0300 |
commit | 942e0b338c9bff1dfdcb59e8308160449f1f38b4 (patch) | |
tree | 4abd1ab238dab3c0af386cb5132f1f5fba9513d4 /src/nvim/eval/decode.c | |
parent | 406562ac6d3863dfdaedbf40f9d4a23ca37c9ec5 (diff) | |
download | rneovim-942e0b338c9bff1dfdcb59e8308160449f1f38b4.tar.gz rneovim-942e0b338c9bff1dfdcb59e8308160449f1f38b4.tar.bz2 rneovim-942e0b338c9bff1dfdcb59e8308160449f1f38b4.zip |
encode: Handle incomplete surrogates like `\uSURR\uOTHR` properly
Diffstat (limited to 'src/nvim/eval/decode.c')
-rw-r--r-- | src/nvim/eval/decode.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index c6706eb0dd..4955a4f5a4 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -459,12 +459,16 @@ json_decode_string_cycle_start: int fst_in_pair = 0; char *str_end = str; bool hasnul = false; +#define PUT_FST_IN_PAIR(fst_in_pair, str_end) \ + do { \ + if (fst_in_pair != 0) { \ + str_end += utf_char2bytes(fst_in_pair, (char_u *) str_end); \ + fst_in_pair = 0; \ + } \ + } while (0) for (const char *t = s; t < p; t++) { if (t[0] != '\\' || t[1] != 'u') { - if (fst_in_pair != 0) { - str_end += utf_char2bytes(fst_in_pair, (char_u *) str_end); - fst_in_pair = 0; - } + PUT_FST_IN_PAIR(fst_in_pair, str_end); } if (*t == '\\') { t++; @@ -489,6 +493,7 @@ json_decode_string_cycle_start: str_end += utf_char2bytes(full_char, (char_u *) str_end); fst_in_pair = 0; } else { + PUT_FST_IN_PAIR(fst_in_pair, str_end); str_end += utf_char2bytes((int) ch, (char_u *) str_end); } break; @@ -522,9 +527,8 @@ json_decode_string_cycle_start: *str_end++ = *t; } } - if (fst_in_pair != 0) { - str_end += utf_char2bytes((int) fst_in_pair, (char_u *) str_end); - } + PUT_FST_IN_PAIR(fst_in_pair, str_end); +#undef PUT_FST_IN_PAIR if (conv.vc_type != CONV_NONE) { size_t str_len = (size_t) (str_end - str); char *const new_str = (char *) string_convert(&conv, (char_u *) str, |