aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/secure.lua
diff options
context:
space:
mode:
authorBarrett Ruth <62671086+barrettruth@users.noreply.github.com>2026-04-23 15:01:37 -0400
committerGitHub <noreply@github.com>2026-04-23 15:01:37 -0400
commit0a8218a2b40fa8f6b533605db4377ff89250711c (patch)
tree179f421f89984739b70b5b903a96a19a47f159a4 /runtime/lua/vim/secure.lua
parent398f2c108d8ee3ce7ac950b60520a9569b63da67 (diff)
downloadrneovim-0a8218a2b40fa8f6b533605db4377ff89250711c.tar.gz
rneovim-0a8218a2b40fa8f6b533605db4377ff89250711c.tar.bz2
rneovim-0a8218a2b40fa8f6b533605db4377ff89250711c.zip
fix(trust): hash unchanged empty buffers as empty files #39027
Problem: `vim.secure.trust()` hashes an unchanged empty buffer as a newline, so trusting an empty file by buffer never works. Solution: Hash unchanged empty-buffers `''` so buffer-based trust matches the on-disk empty file.
Diffstat (limited to 'runtime/lua/vim/secure.lua')
-rw-r--r--runtime/lua/vim/secure.lua17
1 files changed, 12 insertions, 5 deletions
diff --git a/runtime/lua/vim/secure.lua b/runtime/lua/vim/secure.lua
index 9f5463ac98..4a89139679 100644
--- a/runtime/lua/vim/secure.lua
+++ b/runtime/lua/vim/secure.lua
@@ -39,11 +39,18 @@ local function compute_hash(fullpath, bufnr)
end
if bufnr then
- local newline = vim.bo[bufnr].fileformat == 'unix' and '\n' or '\r\n'
- contents =
- table.concat(vim.api.nvim_buf_get_lines(bufnr --[[@as integer]], 0, -1, false), newline)
- if vim.bo[bufnr].endofline then
- contents = contents .. newline
+ local is_unchanged_empty = vim.api.nvim_buf_call(bufnr, function()
+ return not vim.bo[bufnr].modified and vim.fn.line2byte(1) == -1
+ end)
+ if is_unchanged_empty then
+ contents = ''
+ else
+ local newline = vim.bo[bufnr].fileformat == 'unix' and '\n' or '\r\n'
+ contents =
+ table.concat(vim.api.nvim_buf_get_lines(bufnr --[[@as integer]], 0, -1, false), newline)
+ if vim.bo[bufnr].endofline then
+ contents = contents .. newline
+ end
end
else
do