Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numfmt: allow ' ' as field separator #4096

Merged
merged 1 commit into from
Nov 2, 2022
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
2 changes: 1 addition & 1 deletion src/uu/numfmt/src/numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn parse_options(args: &ArgMatches) -> Result<NumfmtOptions> {

let fields = args.get_one::<String>(options::FIELD).unwrap().as_str();
// a lone "-" means "all fields", even as part of a list of fields
let fields = if fields.split(',').any(|x| x == "-") {
let fields = if fields.split(&[',', ' ']).any(|x| x == "-") {
vec![Range {
low: 1,
high: std::usize::MAX,
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/mods/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Range {
pub fn from_list(list: &str) -> Result<Vec<Self>, String> {
let mut ranges = Vec::new();

for item in list.split(',') {
for item in list.split(&[',', ' ']) {
let range_item = FromStr::from_str(item)
.map_err(|e| format!("range {} was invalid: {}", item.quote(), e))?;
ranges.push(range_item);
Expand Down
7 changes: 6 additions & 1 deletion tests/by-util/test_numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ fn test_format_selected_fields() {
.args(&["--from=auto", "--field", "1,4,3", "1K 2K 3K 4K 5K 6K"])
.succeeds()
.stdout_only("1000 2K 3000 4000 5K 6K\n");

new_ucmd!()
.args(&["--from=auto", "--field", "1,4 3", "1K 2K 3K 4K 5K 6K"])
.succeeds()
.stdout_only("1000 2K 3000 4000 5K 6K\n");
}

#[test]
Expand Down Expand Up @@ -401,7 +406,7 @@ fn test_format_selected_field_range() {

#[test]
fn test_format_all_fields() {
let all_fields_patterns = vec!["-", "-,3", "3,-", "1,-,3"];
let all_fields_patterns = vec!["-", "-,3", "3,-", "1,-,3", "- 3"];

for pattern in all_fields_patterns {
new_ucmd!()
Expand Down