Repository: uutils/coreutils (language: rust)

Issue:
numfmt: --from-iec-i should accept arguments without suffix
Environment: Ubuntu 24.04, uutils `main` branch (git commit 2430e2a396d5f5ae29413081b065a4503245839b), GNU coreutils v9.6.8-fbfd88-dirty

Steps to reproduce:
```
numfmt --from=iec-i 1
```

What happens now: uutils `numfmt` complains about a missing suffix:
```
numfmt: missing 'i' suffix in input: '1' (e.g Ki/Mi/Gi)
```

What I expected to happen: GNU `numfmt` succeeds, assuming the number is given in bytes:
```
1
```

Notes: this is causing a failure in the GNU test file `tests/misc/numfmt.pl`.


Discussion / hints:
hey im interested in helping with this. Can this be Assigned to me?
@melonSorbet yes, you can work on it.
```
$ numfmt --from=iec-i 1
numfmt: missing 'i' suffix in input: ‘1’ (e.g Ki/Mi/Gi)
$ numfmt --version
numfmt (GNU coreutils) 9.5
Copyright (C) 2024 Free Software Foundation, Inc.
```

Am I misunderstanding this issue, @jfinkels ?
🤦 I see now: `GNU coreutils v9.6.8-fbfd88-dirty` 
Tho what's the targeted version? 
Recent change/fix indeed. 

<details>

```diff
commit 6229ac946e6ee36158db1a592279671d79a9737a
Author: Pádraig Brady 
Date:   Mon Dec 30 22:48:14 2024 +0000

    numfmt: don't require a suffix with --from=iec-i
    
    * src/numfmt.c (simple_strtod_human): Only look for 'i'
    after detecting a suffix.
    * tests/misc/numfmt.pl: Add a test case.
    * NEWS: Mention the bug fix.
    Reported at https://bugs.debian.org/1091758

diff --git a/NEWS b/NEWS
index f76393506..fff58de81 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   Previously it would have ignored the affinity mask on such systems.
   [bug introduced with nproc in coreutils-8.1]
 
+  numfmt --from=iec-i now works with numbers without a suffix.
+  Previously such numbers were rejected with an error.
+  [bug introduced with numfmt in coreutils-8.21]
+
   printf now diagnoses attempts to treat empty strings as numbers,
   as per POSIX. For example, "printf '%d' ''" now issues a diagnostic
   and fails instead of silently succeeding.
diff --git a/src/numfmt.c b/src/numfmt.c
index a9f9e81c8..99c58aee1 100644
--- a/src/numfmt.c
+++ b/src/numfmt.c
@@ -667,18 +667,17 @@ simple_strtod_human (char const *input_str,
           devmsg ("  Auto-scaling, found 'i', switching to base %d\n",
                   scale_base);
         }
+      else if (allowed_scaling == scale_IEC_I)
+        {
+          if (**endptr == 'i')
+            (*endptr)++;
+          else
+            return SSE_MISSING_I_SUFFIX;
+        }
 
       *precision = 0;  /* Reset, to select precision based on scale.  */
     }
 
-  if (allowed_scaling == scale_IEC_I)
-    {
-      if (**endptr == 'i')
-        (*endptr)++;
-      else
-        return SSE_MISSING_I_SUFFIX;
-    }
-
   long double multiplier = powerld (scale_base, power);
 
   devmsg ("  suffix power=%d^%d = %Lf\n", scale_base, power, multiplier);
diff --git a/tests/misc/numfmt.pl b/tests/misc/numfmt.pl
index 94f9ec58e..148d9d80c 100755
--- a/tests/misc/numfmt.pl
+++ b/tests/misc/numfmt.pl
@@ -41,6 +41,7 @@ my @Tests =
      ['4', '--from=auto 1K',   {OUT => "1000"}],
      ['5', '--from=auto 1Ki',  {OUT => "1024"}],
      ['5.1', '--from=iec-i 1Ki',  {OUT => "1024"}],
+     ['5.2', '--from=iec-i 1',  {OUT => "1"}],
 
      ['6', {IN_PIPE => "1234\n"},            {OUT => "1234"}],
      ['7', '--from=si', {IN_PIPE => "2K\n"}, {OUT => "2000"}],
```

</details>

Makes sense...

Fix patch:
diff --git a/src/uu/numfmt/src/format.rs b/src/uu/numfmt/src/format.rs
index 5933092f62f..e90abc800e6 100644
--- a/src/uu/numfmt/src/format.rs
+++ b/src/uu/numfmt/src/format.rs
@@ -135,9 +135,6 @@ fn remove_suffix(i: f64, s: Option<Suffix>, u: &Unit) -> Result<f64> {
             RawSuffix::Z => Ok(i * IEC_BASES[7]),
             RawSuffix::Y => Ok(i * IEC_BASES[8]),
         },
-        (None, &Unit::Iec(true)) => {
-            Err(format!("missing 'i' suffix in input: '{i}' (e.g Ki/Mi/Gi)"))
-        }
         (Some((raw_suffix, false)), &Unit::Iec(true)) => Err(format!(
             "missing 'i' suffix in input: '{i}{raw_suffix:?}' (e.g Ki/Mi/Gi)"
         )),


Test patch:
diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs
index 7569465ea18..f20315a1cc9 100644
--- a/tests/by-util/test_numfmt.rs
+++ b/tests/by-util/test_numfmt.rs
@@ -56,17 +56,19 @@ fn test_from_iec_i() {
 
 #[test]
 fn test_from_iec_i_requires_suffix() {
-    let numbers = vec!["1024", "10M"];
+    new_ucmd!()
+        .args(&["--from=iec-i", "10M"])
+        .fails()
+        .code_is(2)
+        .stderr_is("numfmt: missing 'i' suffix in input: '10M' (e.g Ki/Mi/Gi)\n");
+}
 
-    for number in numbers {
-        new_ucmd!()
-            .args(&["--from=iec-i", number])
-            .fails()
-            .code_is(2)
-            .stderr_is(format!(
-                "numfmt: missing 'i' suffix in input: '{number}' (e.g Ki/Mi/Gi)\n"
-            ));
-    }
+#[test]
+fn test_from_iec_i_without_suffix_are_bytes() {
+    new_ucmd!()
+        .args(&["--from=iec-i", "1024"])
+        .succeeds()
+        .stdout_is("1024\n");
 }
 
 #[test]