script icon indicating copy to clipboard operation
script copied to clipboard

#110 - Fix Slice bug producing a \n when provided with an empty slice

Open hsheikhali1 opened this issue 2 years ago • 0 comments

see #110 for discussion

Resolved a minor bug where Slice was returning an newline when an empty string slice was passed into it.

The expected behaviour:

// Slice creates a pipe containing each element of the supplied slice of
// strings, one per line

result, err := script.ListFiles("/empty/path/")

// result returns ""

The Actual Behaviour:

result, err := script.ListFiles("/empty/path/")

// result returns "\n"

Use Case for PR

This MR will add logic that will tell Slice to check the length of the incoming string slice (len([]string{ ... })) and if it's less than or equal to 0, or if it's empty, it should tell Slice to return a pipe containing an empty string rather than a "\n"

Slice is used often in the script codebase particularly in ListFiles() where the bug was first discovered. This implementation should resolve it.

hsheikhali1 avatar May 11 '22 00:05 hsheikhali1