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
12 changes: 12 additions & 0 deletions src/uu/split/src/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn handle_obsolete(args: impl uucore::Args) -> (Vec<OsString>, Option<String>) {
let mut obs_lines = None;
let mut preceding_long_opt_req_value = false;
let mut preceding_short_opt_req_value = false;
let mut after_double_dash = false;

let filtered_args = args
.filter_map(|os_slice| {
Expand All @@ -84,6 +85,7 @@ fn handle_obsolete(args: impl uucore::Args) -> (Vec<OsString>, Option<String>) {
&mut obs_lines,
&mut preceding_long_opt_req_value,
&mut preceding_short_opt_req_value,
&mut after_double_dash,
)
})
.collect();
Expand All @@ -98,9 +100,19 @@ fn filter_args(
obs_lines: &mut Option<String>,
preceding_long_opt_req_value: &mut bool,
preceding_short_opt_req_value: &mut bool,
after_double_dash: &mut bool,
) -> Option<OsString> {
let filter: Option<OsString>;
if let Some(slice) = os_slice.to_str() {
if *after_double_dash {
// Past `--` everything is an operand, so `split -- -1` names a file
// rather than setting the line count.
return Some(OsString::from(slice));
}
if slice == "--" {
*after_double_dash = true;
return Some(OsString::from(slice));
}
if should_extract_obs_lines(
slice,
*preceding_long_opt_req_value,
Expand Down
12 changes: 12 additions & 0 deletions src/uu/uniq/src/uniq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ fn handle_obsolete(args: impl uucore::Args) -> (Vec<OsString>, Option<usize>, Op
let mut skip_chars_old = None;
let mut preceding_long_opt_req_value = false;
let mut preceding_short_opt_req_value = false;
let mut after_double_dash = false;

let filtered_args = args
.filter_map(|os_slice| {
Expand All @@ -384,6 +385,7 @@ fn handle_obsolete(args: impl uucore::Args) -> (Vec<OsString>, Option<usize>, Op
&mut skip_chars_old,
&mut preceding_long_opt_req_value,
&mut preceding_short_opt_req_value,
&mut after_double_dash,
)
})
.collect();
Expand All @@ -403,9 +405,19 @@ fn filter_args(
skip_chars_old: &mut Option<String>,
preceding_long_opt_req_value: &mut bool,
preceding_short_opt_req_value: &mut bool,
after_double_dash: &mut bool,
) -> Option<OsString> {
let filter: Option<OsString>;
if let Some(slice) = os_slice.to_str() {
if *after_double_dash {
// Past `--` everything is an operand, so `uniq -- -1` names a file
// rather than skipping a field.
return Some(OsString::from(slice));
}
if slice == "--" {
*after_double_dash = true;
return Some(OsString::from(slice));
}
if should_extract_obs_skip_fields(
slice,
*preceding_long_opt_req_value,
Expand Down
10 changes: 10 additions & 0 deletions tests/by-util/test_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2218,3 +2218,13 @@ split: invalid number of bytes: '7zq'
.stderr_is("split: invalid number of bytes: '7zq'\n");
}
}

#[test]
fn test_obsolete_lines_not_read_after_double_dash() {
// After `--` there are no more options, so `-1` names a file rather than
// being taken as the obsolete `split -1` line-count spelling.
new_ucmd!()
.args(&["--", "-1"])
.fails()
.stderr_contains("cannot open '-1' for reading");
}
10 changes: 10 additions & 0 deletions tests/by-util/test_uniq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,3 +1220,13 @@ fn test_failed_write_is_reported() {
.fails()
.stderr_is("uniq: write error: No space left on device\n");
}

#[test]
fn test_obsolete_skip_fields_not_read_after_double_dash() {
// After `--` there are no more options, so `-1` names a file rather than
// being taken as the obsolete "skip 1 field" spelling.
new_ucmd!()
.args(&["--", "-1"])
.fails()
.stderr_contains("-1");
}