Skip to content

Commit

Permalink
calcHash: use correct line endings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmaluka committed Aug 17, 2024
1 parent 5468b56 commit 57edb8f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,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
Expand Down

0 comments on commit 57edb8f

Please sign in to comment.