Refactor: Replace strings.Split with SplitList utility to handle empty inputs#789
Open
xnaveenx wants to merge 2 commits intolitmuschaos:masterfrom
Open
Refactor: Replace strings.Split with SplitList utility to handle empty inputs#789xnaveenx wants to merge 2 commits intolitmuschaos:masterfrom
xnaveenx wants to merge 2 commits intolitmuschaos:masterfrom
Conversation
Signed-off-by: Naveen <107784608+xnaveenx@users.noreply.github.com>
…y inputs Signed-off-by: xnaveenx <naveen010210@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
This PR refactors the usage of
strings.Splitacross the codebase to use thestringutils.SplitListutility (27 files changed).The Problem:
The standard
strings.Split("", ",")returns a slice containing an empty string[""](length 1). This causes logic errors in experiments where code checkslen(slice) > 0or iterates over the slice assuming it contains valid values, potentially leading to index out-of-range panics or invalid execution paths.The Fix:
I have replaced
strings.Splitwithstringutils.SplitListin user-input handling paths. This utility correctly returns an empty slice[](length 0) when the input string is empty.Changes Covered:
pkg/utils/common/pods.go,pkg/utils/common/nodes.gopkg/status/nodes.go,pkg/status/application.gopkg/cloud/*.chaoslib/(e.g., Disk Loss, Instance Stop, Node Drain).experiments/kube-aws/ec2-terminate-by-id.Which issue this PR fixes : fixes #788
Special notes for your reviewer:
go build ./...passes successfully across the entire project to ensure no dependencies were broken.go test -v github.com/litmuschaos/litmus-go/pkg/utils/stringutilspasses.chaoslib/litmus/network-chaos/helper/netem.gofrom this refactor as it contains custom parsing logic (whitelisting with!) that requiresstrings.Splitbehavior.Checklist:
breaking-changestagrequires-upgradetag