aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/buffer.c20
-rw-r--r--src/nvim/api/vim.c6
2 files changed, 24 insertions, 2 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 982003a31a..0292e82038 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -132,7 +132,12 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer,
}
const char *bufstr = (char *) ml_get_buf(buf, (linenr_T) lnum, false);
- rv.items[i] = STRING_OBJ(cstr_to_string(bufstr));
+ Object str = STRING_OBJ(cstr_to_string(bufstr));
+
+ // Vim represents NULs as NLs, but this may confuse clients.
+ strchrsub(str.data.string.data, '\n', '\0');
+
+ rv.items[i] = str;
}
end:
@@ -201,7 +206,18 @@ void buffer_set_line_slice(Buffer buffer,
}
String l = replacement.items[i].data.string;
- lines[i] = xmemdupz(l.data, l.size);
+
+ // Fill lines[i] with l's contents. Disallow newlines in the middle of a
+ // line and convert NULs to newlines to avoid truncation.
+ lines[i] = xmallocz(l.size);
+ for (size_t j = 0; j < l.size; j++) {
+ if (l.data[j] == '\n') {
+ api_set_error(err, Exception, _("string cannot contain newlines"));
+ new_len = i + 1;
+ goto end;
+ }
+ lines[i][j] = (char) (l.data[j] == '\0' ? '\n' : l.data[j]);
+ }
}
try_start();
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index fe5fa6274b..eab79d970e 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -21,6 +21,7 @@
#include "nvim/message.h"
#include "nvim/eval.h"
#include "nvim/misc2.h"
+#include "nvim/syntax.h"
#include "nvim/term.h"
#include "nvim/getchar.h"
#include "nvim/os/input.h"
@@ -546,6 +547,11 @@ void vim_unsubscribe(uint64_t channel_id, String event)
channel_unsubscribe(channel_id, e);
}
+Integer vim_name_to_color(String name)
+{
+ return name_to_color((uint8_t *)name.data);
+}
+
Array vim_get_api_info(uint64_t channel_id)
{
Array rv = ARRAY_DICT_INIT;