diff --git a/util/util.go b/util/util.go index e127f524..03ee4254 100644 --- a/util/util.go +++ b/util/util.go @@ -33,6 +33,9 @@ import ( // you specify 0, you'll get `a`, 25 gives you `z`, and 26 gives you `aa` and so // on... func NumToAlpha(idx int) string { + if idx < 0 { + return "" // don't error or produce junk + } var mod = idx % 26 var div = idx / 26 if div > 0 { diff --git a/util/util_test.go b/util/util_test.go index 07609f08..8070f52a 100644 --- a/util/util_test.go +++ b/util/util_test.go @@ -38,6 +38,7 @@ func TestNumToAlpha(t *testing.T) { {702, "aaa"}, {703, "aab"}, {63269, "cool"}, + {-1, ""}, } for _, test := range numToAlphaTests {