Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render files that have a byte-order-marker properly #327

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion babi/buf.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def tab_string(self) -> str:

def rendered_line(self, idx: int, dim: Dim) -> str:
x = self._cursor_x if idx == self.y else 0
expanded = self._lines[idx].expandtabs(self.tab_size)
expanded = self._lines[idx].expandtabs(self.tab_size).lstrip('\ufeff')
return scrolled_line(expanded, x, dim.width)

# movement
Expand Down
11 changes: 11 additions & 0 deletions tests/features/save_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ def test_mixed_newlines(run, tmpdir):
h.await_text(r"mixed newlines will be converted to '\n'")


def test_byte_order_marker(run, tmpdir):
src = b'\xef\xbb\xbfhello\n'
f = tmpdir.join('f')
f.write_binary(src)
with run(str(f)) as h, and_exit(h):
# renders ok without an extra space for BOM
h.await_text('\nhello\n')
h.press('^S')
assert f.read_binary() == src


def test_modify_file_with_windows_newlines(run, tmpdir):
f = tmpdir.join('f')
f.write_binary(b'foo\r\nbar\r\n')
Expand Down