From 72ea3e9b2b8bcd0107d6c8ee678869d8d5d6bfc9 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Sat, 13 Jun 2026 22:39:16 +0200 Subject: [PATCH] fix(formatter): guard ShortenID/SmallSHA against short input ShortenID and SmallSHA sliced their input to a fixed length without checking it was long enough, panicking on shorter strings. Return the input unchanged when it is already shorter than the cut. Also replace the blank Commit placeholder with an explicit "unknown-commit" sentinel. --- cmd/abra/main.go | 2 +- pkg/formatter/formatter.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/abra/main.go b/cmd/abra/main.go index d31d1e82..514583ad 100644 --- a/cmd/abra/main.go +++ b/cmd/abra/main.go @@ -16,7 +16,7 @@ func main() { Version = "dev" } if Commit == "" { - Commit = " " + Commit = "unknown-commit" } cli.Run(Version, Commit) diff --git a/pkg/formatter/formatter.go b/pkg/formatter/formatter.go index 1ffca2f7..ab5f0f39 100644 --- a/pkg/formatter/formatter.go +++ b/pkg/formatter/formatter.go @@ -27,10 +27,16 @@ var BoldUnderlineStyle = lipgloss.NewStyle(). Underline(true) func ShortenID(str string) string { + if len(str) < 12 { + return str + } return str[:12] } func SmallSHA(hash string) string { + if len(hash) < 8 { + return hash + } return hash[:8] }