Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic in DefaultNamifier #234

Closed
nickchen opened this issue Jun 18, 2024 · 3 comments
Closed

panic in DefaultNamifier #234

nickchen opened this issue Jun 18, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@nickchen
Copy link
Contributor

sentence = strings.ToUpper(sentence[:1]) + sentence[1:]

go: downloading github.com/lerenn/asyncapi-codegen v0.41.3
panic: runtime error: slice bounds out of range [:1] with length 0

goroutine 1 [running]:
github.com/lerenn/asyncapi-codegen/pkg/utils/template.DefaultNamifier({0x10331f418, 0x1})
	/Users/nickchen/go/pkg/mod/github.com/lerenn/[email protected]/pkg/utils/template/helpers.go:66 +0x30c
github.com/lerenn/asyncapi-codegen/pkg/utils/template.Namify(...)

Propose fix:

diff --git a/pkg/utils/template/helpers.go b/pkg/utils/template/helpers.go
index 0d5c21c..2491a2e 100644
--- a/pkg/utils/template/helpers.go
+++ b/pkg/utils/template/helpers.go
@@ -61,7 +61,9 @@ func DefaultNamifier(sentence string) string {
        // Remove leading numbers
        re = regexp.MustCompile("^[0-9]+")
        sentence = string(re.ReplaceAll([]byte(sentence), []byte("")))
-
+       if len(sentence) == 0 {
+               return sentence
+       }
        // Upper first letter
        sentence = strings.ToUpper(sentence[:1]) + sentence[1:]
@lerenn
Copy link
Owner

lerenn commented Jun 18, 2024

Hello @nickchen ! Thanks for reporting this bug !
The fix looks great !

I can create the MR and merge it for you, but if you prefer to do it and be credited in the Github contributors, let me know !

@lerenn lerenn self-assigned this Jun 18, 2024
@lerenn lerenn added the bug Something isn't working label Jun 18, 2024
@nickchen
Copy link
Contributor Author

#236 here you go. Ran into couple of other issues, will open separate PR for them.

@lerenn
Copy link
Owner

lerenn commented Jun 20, 2024

Thanks for opening those issues/PR. It's really helpful for the project :)

I'll close this issue, as you solved it in a now merged PR.

@lerenn lerenn closed this as completed Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants