#42188·neovim

Statusline/`'titlestring'` 使用 `maxwidth` 截断导致缓冲区未终止: `set_title` (以及 `nvim_eval_statusline()`) 中的 UTF-8 无效

作者: creabos创建于 2026年9月30日更新于 2026年10月1日
标签revisit-at-releasestatusline

Minimal, Nvim only ("nvim --clean --headless -l min.lua"):

lua
local function valid(s) -- strict UTF-8 check
  local i, n = 1, #s
  while i <= n do
    local c = s:byte(i)
    local k = c < 0x80 and 0 or (c >= 0xC2 and c <= 0xDF) and 1 or (c >= 0xE0 and c <= 0xEF) and 2 or (c >= 0xF0 and c <= 0xF4) and 3 or nil
    if not k then return false end
    for j = 1, k do local d = s:byte(i + j); if not d or d < 0x80 or d > 0xBF then return false end end
    i = i + 1 + k
  end
  return true
end
local s = vim.api.nvim_eval_statusline("%{'あいうえおかきくけこ'}", { maxwidth = 8 })
print(vim.inspect(s.str), "valid UTF-8:", valid(s.str))

Actual output on 0.12.5: