Skip to content

Commit

Permalink
Fix handling of binary input
Browse files Browse the repository at this point in the history
Gracefully handle binary input with from_utf8_lossy.

Fixes #189
  • Loading branch information
rcoh committed May 19, 2023
1 parent 27c2c38 commit 4689b4c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ pub mod pipeline {
if ct == 0 {
break;
}
let data = std::str::from_utf8(&line[..ct]).unwrap();
if self.filter.matches(data)
let data = String::from_utf8_lossy(&line[..ct]);
if self.filter.matches(data.as_ref())
&& !Pipeline::proc_preagg(Record::new(data), &mut preaggs, &tx)
{
break;
Expand Down
3 changes: 3 additions & 0 deletions test_files/binary_data.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
line of regular text k=v2
�K���@�V ���+P��Q�Þ�0����S��oU�!+��X-!����޴A�� �r��[�OC��j_kΕ����V����5; �x1rYuV���
line of regular text k=v
12 changes: 12 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ None 1\n",
);
}

#[test]
fn binary_input() {
run()
.args([
"* | parse 'k=*' as k",
"--file",
"test_files/binary_data.bin",
])
.assert()
.stdout("[k=v2]\n[k=v]\n");
}

#[test]
fn filter_wildcard() {
run()
Expand Down

0 comments on commit 4689b4c

Please sign in to comment.