Skip to content

Commit c0f6b65

Browse files
committed
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.
1 parent e0f5361 commit c0f6b65

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

internal/buffer/buffer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,11 @@ func calcHash(b *Buffer, out *[md5.Size]byte) error {
658658
size += n
659659

660660
for _, l := range b.lines[1:] {
661-
n, _ = h.Write([]byte{'\n'})
661+
if b.Endings == FFDos {
662+
n, _ = h.Write([]byte{'\r', '\n'})
663+
} else {
664+
n, _ = h.Write([]byte{'\n'})
665+
}
662666
size += n
663667
n, _ = h.Write(l.data)
664668
size += n

0 commit comments

Comments
 (0)