Skip to content
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
9 changes: 4 additions & 5 deletions src/uu/echo/src/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::env;
use std::ffi::{OsStr, OsString};
use std::io::{self, StdoutLock, Write};
use uucore::error::{UResult, USimpleError};
use uucore::format::{EscapedChar, FormatChar, OctalParsing, parse_escape_only};
use uucore::format::{FormatChar, OctalParsing, parse_escape_only};
use uucore::{format_usage, help_about, help_section, help_usage};

const ABOUT: &str = help_about!("echo.md");
Expand Down Expand Up @@ -150,10 +150,9 @@ fn execute(

if escaped {
for item in parse_escape_only(bytes, OctalParsing::ThreeDigits) {
match item {
EscapedChar::End => return Ok(()),
c => c.write(&mut *stdout_lock)?,
};
if item.write(&mut *stdout_lock)?.is_break() {
return Ok(());
}
}
} else {
stdout_lock.write_all(bytes)?;
Expand Down
4 changes: 3 additions & 1 deletion src/uucore/src/lib/features/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ fn printf_writer<'a>(
let args = args.into_iter().cloned().collect::<Vec<_>>();
let mut args = FormatArguments::new(&args);
for item in parse_spec_only(format_string.as_ref()) {
item?.write(&mut writer, &mut args)?;
if item?.write(&mut writer, &mut args)?.is_break() {
break;
}
}
Ok(())
}
Expand Down
9 changes: 9 additions & 0 deletions tests/by-util/test_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,12 @@ fn test_uchild_when_run_no_wait_with_a_non_blocking_util() {
// we should be able to call wait without panics and apply some assertions
child.wait().unwrap().code_is(0).no_stdout().no_stderr();
}

#[test]
fn test_escape_sequence_ctrl_c() {
new_ucmd!()
.args(&["-e", "show\\c123"])
.run()
.success()
.stdout_only("show");
}
Loading