fix: isHashID matches for hyphenated application names

Fixes `isHashID` checks for hyphenated application names

When a user calls bd init inside an application that has a "-" for
example my-first-application without any options than ids will follow a
pattern of my-first-application-{ID}. When using SplitN on the "-"
separator it would result in the split parts returning as [my,
first-application-{ID}] which is incorrectly pulling out the {ID}
resulting in the `isHashID` returning false when it could be a hash id.

Instead of using SplitN, this changes to find the last index of the
separator resulting in the suffix becoming the actual {ID}.
This commit is contained in:
Zachary Rosen
2025-11-15 22:06:21 -05:00
committed by Steve Yegge
parent 7b865eb541
commit 408244ed73
2 changed files with 12 additions and 4 deletions

View File

@@ -328,12 +328,12 @@ func replaceIDReferences(text string, mapping map[string]string) string {
func isHashID(id string) bool {
// Hash IDs contain hex letters (a-f), sequential IDs are only digits
// May have hierarchical suffix like .1 or .1.2
parts := strings.SplitN(id, "-", 2)
if len(parts) != 2 {
lastSeperatorIndex := strings.LastIndex(id, "-")
if lastSeperatorIndex == -1 {
return false
}
suffix := parts[1]
suffix := id[lastSeperatorIndex+1:]
// Strip hierarchical suffix like .1 or .1.2
baseSuffix := strings.Split(suffix, ".")[0]