Skip to content

Commit 1371006

Browse files
committed
fix: handle non utf-8 input in stdin and file reading tasks
1 parent 04ada23 commit 1371006

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/app.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -821,14 +821,14 @@ fn handle_input_task(tx: Sender<Action>) -> Result<()> {
821821
}
822822

823823
fn read_stdin_task(action_tx: Sender<Action>) -> Result<()> {
824-
let mut buff = String::new();
824+
let mut buff = vec![];
825825
let tty = stdin().is_tty();
826826
if !tty {
827-
let result = stdin().read_to_string(&mut buff);
828-
827+
let result = stdin().read_to_end(&mut buff);
829828
match result {
830829
Ok(_) => {
831-
action_tx.send(StdinRead(buff))?;
830+
let content = String::from_utf8_lossy(&buff);
831+
action_tx.send(StdinRead(content.into_owned()))?;
832832
}
833833
Err(e) => {
834834
action_tx.send(StdinReadFailed(format!(
@@ -845,10 +845,10 @@ fn read_stdin_task(action_tx: Sender<Action>) -> Result<()> {
845845

846846
fn read_file_task(file: String, action_tx: Sender<Action>) -> Result<()> {
847847
info!("reading input file {file}");
848-
let file_content = std::fs::read_to_string(file.clone());
849-
match file_content {
848+
match std::fs::read(file.clone()) {
850849
Ok(content) => {
851-
action_tx.send(StdinRead(content))?;
850+
let content = String::from_utf8_lossy(&content);
851+
action_tx.send(StdinRead(content.into_owned()))?;
852852
}
853853
Err(e) => {
854854
action_tx.send(StdinReadFailed(format!(

0 commit comments

Comments
 (0)