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:
committed by
Steve Yegge
parent
7b865eb541
commit
408244ed73
@@ -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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user