Skip to content

Refactor: Replace strings.Split with SplitList utility to handle empty inputs#789

Open
xnaveenx wants to merge 2 commits intolitmuschaos:masterfrom
xnaveenx:refactor/splitlist-utility
Open

Refactor: Replace strings.Split with SplitList utility to handle empty inputs#789
xnaveenx wants to merge 2 commits intolitmuschaos:masterfrom
xnaveenx:refactor/splitlist-utility

Conversation

@xnaveenx
Copy link
Contributor

What this PR does / why we need it:
This PR refactors the usage of strings.Split across the codebase to use the stringutils.SplitList utility (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 checks len(slice) > 0 or 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.Split with stringutils.SplitList in user-input handling paths. This utility correctly returns an empty slice [] (length 0) when the input string is empty.

Changes Covered:

  • Core Utils: pkg/utils/common/pods.go, pkg/utils/common/nodes.go
  • Status Checks: pkg/status/nodes.go, pkg/status/application.go
  • Cloud Helpers: Updated status and helper files for AWS, Azure, GCP, and VMware in pkg/cloud/*.
  • Chaos Libraries: Updated corresponding libraries in chaoslib/ (e.g., Disk Loss, Instance Stop, Node Drain).
  • AWS Experiment: Fixed the entry point in experiments/kube-aws/ec2-terminate-by-id.

Which issue this PR fixes : fixes #788

Special notes for your reviewer:

  • Validated that go build ./... passes successfully across the entire project to ensure no dependencies were broken.
  • Verified that go test -v github.com/litmuschaos/litmus-go/pkg/utils/stringutils passes.
  • Note: I intentionally excluded chaoslib/litmus/network-chaos/helper/netem.go from this refactor as it contains custom parsing logic (whitelisting with !) that requires strings.Split behavior.

Checklist:

  • Fixes Refactor: Replace inline string splitting with robust SplitList utility #788
  • PR messages has document related information
  • Labelled this PR & related issue with breaking-changes tag
  • PR messages has breaking changes related information
  • Labelled this PR & related issue with requires-upgrade tag
  • PR messages has upgrade related information
  • Commit has unit tests
  • Commit has integration tests
  • E2E run Required for the changes

xnaveenx and others added 2 commits January 27, 2026 13:34
Signed-off-by: Naveen <107784608+xnaveenx@users.noreply.github.com>
…y inputs

Signed-off-by: xnaveenx <naveen010210@gmail.com>
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

Successfully merging this pull request may close these issues.

Refactor: Replace inline string splitting with robust SplitList utility

1 participant