← back to Cli Printing Press
fix(cli): use strconv.Atoi for major-version parsing in guard test (#300)
0cc70170f37f8dc6c5e38b6253ed03cec64ae5ed · 2026-04-26 00:17:38 -0700 · Trevin Chow
fmt.Sscanf with %d returns no error on input like "2abc" — it stops
at the first non-digit and returns 2. That would mask a malformed
Version constant in TestModulePathMatchesMajorVersion's helper.
TestVersionIsValidSemver already enforces ^\d+\.\d+\.\d+$, so this
is defense in depth rather than a live bug. strconv.Atoi rejects
trailing junk and is the idiomatic choice for "this string must be
exactly an int."
Files touched
M internal/cli/release_test.go
Diff
commit 0cc70170f37f8dc6c5e38b6253ed03cec64ae5ed
Author: Trevin Chow <trevin@trevinchow.com>
Date: Sun Apr 26 00:17:38 2026 -0700
fix(cli): use strconv.Atoi for major-version parsing in guard test (#300)
fmt.Sscanf with %d returns no error on input like "2abc" — it stops
at the first non-digit and returns 2. That would mask a malformed
Version constant in TestModulePathMatchesMajorVersion's helper.
TestVersionIsValidSemver already enforces ^\d+\.\d+\.\d+$, so this
is defense in depth rather than a live bug. strconv.Atoi rejects
trailing junk and is the idiomatic choice for "this string must be
exactly an int."
---
internal/cli/release_test.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/internal/cli/release_test.go b/internal/cli/release_test.go
index 04e6222f..3536380f 100644
--- a/internal/cli/release_test.go
+++ b/internal/cli/release_test.go
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"regexp"
+ "strconv"
"strings"
"testing"
@@ -137,8 +138,7 @@ func majorVersion(t *testing.T, v string) int {
t.Helper()
parts := strings.SplitN(v, ".", 2)
require.NotEmpty(t, parts[0], "Version must have a major component")
- var major int
- _, err := fmt.Sscanf(parts[0], "%d", &major)
+ major, err := strconv.Atoi(parts[0])
require.NoError(t, err, "Version major %q must be an integer", parts[0])
return major
}
← 1ab789ea fix(cli): use /v2 module path so go install reports correct
·
back to Cli Printing Press
·
chore(main): release 2.3.7 (#299) 574fc27d →