Fix case where trailing newlines at the end of the file weren't being truncated