Skip to content

Panics when no classes or empty classes are set as args #11

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

Closed
rotmh opened this issue Sep 8, 2024 · 3 comments
Closed

Panics when no classes or empty classes are set as args #11

rotmh opened this issue Sep 8, 2024 · 3 comments

Comments

@rotmh
Copy link

rotmh commented Sep 8, 2024

When the input for twmerge.Merge is nothing, or just empty strings, the program panics.

panic: runtime error: index out of range [0] with length 0
...
twmerge/modifier-utils.go:41
...
twmerge.Merge("")  // panics
twmerge.Merge()    // panics

I don't think it's an expected or wanted behavior, and it can be fixed simply by creating a wrapper for the Merge function, to ensure there is no empty strings, and if there are only empty strings, just return an empty string, e.g.:

var SafeMerge = func(args ...string) string {
	var nonEmptyArgs []string
	for _, arg := range args {
		if arg != "" {
			nonEmptyArgs = append(nonEmptyArgs, arg)
		}
	}
	if len(nonEmptyArgs) == 0 {
		return ""
	}
	return twmerge.Merge(nonEmptyArgs...)
}

But I think it would be best to handle it in the package itself.

@Oudwins
Copy link
Owner

Oudwins commented Sep 8, 2024

Oh wow. This is quite a blunder on my part. I am sorry and thank you so much for reporting it. It will be fixed in a bit. Please update to the latest version

@Oudwins
Copy link
Owner

Oudwins commented Sep 8, 2024

Closing this now since it has been fixed in #12 update to v0.2.0.

@Oudwins Oudwins closed this as completed Sep 8, 2024
@rotmh
Copy link
Author

rotmh commented Sep 8, 2024

Upgraded and working fine. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants