From c0f6b65ed628bd86946e49d77ca84397ba3e40a5 Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Sat, 17 Aug 2024 16:56:15 +0200 Subject: [PATCH] calcHash: use correct line endings Make calcHash() respect the buffer's file endings (unix vs dos), to make its calculation of the file size consistent with how we calculate it in other cases (i.e. when opening or saving the file) and with the `fastdirty` option documentation, i.e. make calcHash() return ErrFileTooLarge if and only if the exact file size exceeds 50KB. --- internal/buffer/buffer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index a7aca541..c1bf6f10 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -658,7 +658,11 @@ func calcHash(b *Buffer, out *[md5.Size]byte) error { size += n for _, l := range b.lines[1:] { - n, _ = h.Write([]byte{'\n'}) + if b.Endings == FFDos { + n, _ = h.Write([]byte{'\r', '\n'}) + } else { + n, _ = h.Write([]byte{'\n'}) + } size += n n, _ = h.Write(l.data) size += n