Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions src/uu/echo/src/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fn handle_double_hyphens(args: impl uucore::Args) -> impl uucore::Args {
let mut result = Vec::new();
let mut is_first_double_hyphen = true;

for arg in args {
if arg == "--" && is_first_double_hyphen {
for (i, arg) in args.enumerate() {
if i < 2 && arg == "--" && is_first_double_hyphen {
result.push(OsString::from("--"));
is_first_double_hyphen = false;
}
Expand Down
20 changes: 19 additions & 1 deletion tests/by-util/test_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ fn test_hyphen_values_between() {
}

#[test]
fn test_double_hyphens() {
fn test_double_hyphens_at_start() {
new_ucmd!().arg("--").succeeds().stdout_only("--\n");
new_ucmd!()
.arg("--")
Expand All @@ -252,6 +252,24 @@ fn test_double_hyphens() {
.stdout_only("-- --\n");
}

#[test]
fn test_double_hyphens_between() {
new_ucmd!()
.arg("a")
.arg("--")
.arg("b")
.succeeds()
.stdout_only("a -- b\n");

new_ucmd!()
.arg("foo ")
.arg("-- --")
.arg("bar")
.arg("hehehe")
Comment thread
Expertcoderz marked this conversation as resolved.
.succeeds()
.stdout_only("foo -- -- bar hehehe\n");
}

#[test]
fn wrapping_octal() {
// Some odd behavior of GNU. Values of \0400 and greater do not fit in the
Expand Down