Skip to content

Commit

Permalink
Fixed issues with cr lf lines in log files
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6368 committed Oct 1, 2023
1 parent 12a0438 commit 5bed8e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions embark/embark/logviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ def refresh(self) -> None:
if len(line) > 0 and line[-1:] == b'\n':
line_ending = line_ending - 1

if len(line) > 1 and line[-2:] == b'\r\n':
line_ending = line_ending - 1

self.line_beginnings.append(line_beginning)
self.line_endings.append(line_ending)

Expand Down
12 changes: 12 additions & 0 deletions embark/embark/tests/test_linecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ def test_default(self):
self.assertEqual(b'10: ggggggggg\n11: hhhhhhhhhhhhh\n', line_cache.read_lines(0, 2), 'The line cache did not return the correct value.')
self.assertEqual(b'9: ffffffffff\n10: ggggggggg\n11: hhhhhhhhhhhhh', line_cache.read_lines(1, 3), 'The line cache did not return the correct value.')

def test_cr_lf(self):
line_cache = LineCache('./test/logviewer/line_cache_test_cr_lf.log')

for _ in range(0, 2):
self.assertEqual(12, line_cache.num_lines(), 'Incorrect number of lines.')
self.assertEqual(len(line_cache.line_endings), len(line_cache.line_beginnings), 'The number of line beginnings and line endings do not match.')
self.assertEqual([0, 7, 10, 22, 30, 40, 49, 52, 55, 69, 83, 102], line_cache.line_beginnings, 'The line beginning cache is not valid.')
line_cache.refresh()

self.assertEqual(b'10: ggggggggg\n11: hhhhhhhhhhhhh\r\n', line_cache.read_lines(0, 2), 'The line cache did not return the correct value.')
self.assertEqual(b'9: ffffffffff\n10: ggggggggg\n11: hhhhhhhhhhhhh', line_cache.read_lines(1, 3), 'The line cache did not return the correct value.')

def test_no_newline_end(self):
line_cache = LineCache('./test/logviewer/line_cache_test_no_newline.log')

Expand Down

0 comments on commit 5bed8e3

Please sign in to comment.