Skip to content

Commit

Permalink
Merge pull request #3701 from cakebaker/comm_nul_delimiter
Browse files Browse the repository at this point in the history
comm: use NUL if delimiter is empty
  • Loading branch information
sylvestre authored Jul 6, 2022
2 parents 43a5b8c + ac35a1b commit 2f46e40
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/uu/comm/src/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ mod options {

fn mkdelim(col: usize, opts: &ArgMatches) -> String {
let mut s = String::new();
let delim = opts.value_of(options::DELIMITER).unwrap();
let delim = match opts.value_of(options::DELIMITER).unwrap() {
"" => "\0",
delim => delim,
};

if col > 1 && !opts.is_present(options::COLUMN_1) {
s.push_str(delim.as_ref());
Expand Down
7 changes: 3 additions & 4 deletions tests/by-util/test_comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ fn output_delimiter() {
.stdout_only_fixture("ab_delimiter_word.expected");
}

#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test]
fn output_delimiter_require_arg() {
fn output_delimiter_nul() {
new_ucmd!()
.args(&["--output-delimiter=", "a", "b"])
.fails()
.stderr_only("error to be defined");
.succeeds()
.stdout_only_fixture("ab_delimiter_nul.expected");
}

// even though (info) documentation suggests this is an option
Expand Down
Binary file added tests/fixtures/comm/ab_delimiter_nul.expected
Binary file not shown.

0 comments on commit 2f46e40

Please sign in to comment.