Skip to content

Commit

Permalink
render files that have a byte-order-marker properly
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Oct 30, 2023
1 parent 8d5c80f commit 7986ef2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit 7986ef2

Please sign in to comment.