From a9cd8467cbd54035e7814b862054c828467c2ce2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Jun 2023 13:59:57 +0800 Subject: [PATCH] fix(api): wrong nvim_buf_set_extmark error for invalid hl_mode --- src/nvim/api/extmark.c | 14 +++++++------- test/functional/api/extmark_spec.lua | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index aca290494b..1946d77846 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -701,7 +701,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer } else if (strequal("inline", str.data)) { decor.virt_text_pos = kVTInline; } else { - VALIDATE_S(false, "virt_text_pos", "", { + VALIDATE_S(false, "virt_text_pos", str.data, { goto error; }); } @@ -719,7 +719,11 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer OPTION_TO_BOOL(decor.virt_text_hide, virt_text_hide, false); OPTION_TO_BOOL(decor.hl_eol, hl_eol, false); - if (opts->hl_mode.type == kObjectTypeString) { + if (HAS_KEY(opts->hl_mode)) { + VALIDATE_T("hl_mode", kObjectTypeString, opts->hl_mode.type, { + goto error; + }); + String str = opts->hl_mode.data.string; if (strequal("replace", str.data)) { decor.hl_mode = kHlModeReplace; @@ -728,14 +732,10 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer } else if (strequal("blend", str.data)) { decor.hl_mode = kHlModeBlend; } else { - VALIDATE_S(false, "virt_text_pos", "", { + VALIDATE_S(false, "hl_mode", str.data, { goto error; }); } - } else if (HAS_KEY(opts->hl_mode)) { - VALIDATE_T("hl_mode", kObjectTypeString, opts->hl_mode.type, { - goto error; - }); } bool virt_lines_leftcol = false; diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 675c8332de..ec1c9245ba 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -105,6 +105,10 @@ describe('API/extmarks', function() it('validation', function() eq("Invalid 'end_col': expected Integer, got Array", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = {}, end_row = 1 })) eq("Invalid 'end_row': expected Integer, got Array", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = {} })) + eq("Invalid 'virt_text_pos': expected String, got Integer", pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 0 })) + eq("Invalid 'virt_text_pos': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 'foo' })) + eq("Invalid 'hl_mode': expected String, got Integer", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 0 })) + eq("Invalid 'hl_mode': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 'foo' })) eq("Invalid 'id': expected positive Integer", pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 })) eq("Invalid mark position: expected 2 Integer items", pcall_err(get_extmarks, ns, {}, {-1, -1})) eq("Invalid mark position: expected mark id Integer or 2-item Array", pcall_err(get_extmarks, ns, true, {-1, -1}))