Skip to content
Open
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: 9 additions & 0 deletions src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// https://github.com/uutils/coreutils/issues/2424#issuecomment-863825242,
// and the same rewrite in `cut`), so rewrite every attached `-t<chars>`
// argument to its long form, which preserves the separator verbatim.
// Arguments after `--` are file operands and must be left untouched.
let mut seen_double_dash = false;
let args = args.into_iter().map(|x| {
if seen_double_dash {
return x;
}
if x == "--" {
seen_double_dash = true;
return x;
}
// Non-UTF-8 separators are rejected later anyway, so lossy conversion
// here only affects arguments that cannot become a valid separator.
let as_str = x.to_string_lossy();
Expand Down
9 changes: 9 additions & 0 deletions tests/by-util/test_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,15 @@ fn test_separator_attached_equals() {
.stdout_only("b=a=d\na=b=c\n");
}

#[test]
fn test_separator_like_file_operand_after_double_dash() {
// After `--`, a file named `-t=` is an operand and must not be rewritten
// to `--field-separator==`.
let (at, mut ucmd) = at_and_ucmd!();
at.write("-t=", "b\na\n");
ucmd.args(&["--", "-t="]).succeeds().stdout_only("a\nb\n");
}

#[test]
fn test_separator_attached_equals_double() {
// `-t==` selects the two-character separator `==`, which GNU rejects.
Expand Down
Loading