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

fix: utils.Trim should trim all string content #1775

Merged
merged 3 commits into from Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions utils/strings.go
Expand Up @@ -49,6 +49,12 @@ func Trim(s string, cutset byte) string {
}
}

if i == j {
if s[i] == cutset {
return ""
}
}

return s[i : j+1]
}

Expand Down
9 changes: 9 additions & 0 deletions utils/strings_test.go
Expand Up @@ -126,6 +126,15 @@ func Test_Trim(t *testing.T) {

res = Trim(".test", '.')
AssertEqual(t, "test", res)

res = Trim(" ", ' ')
AssertEqual(t, "", res)

res = Trim(" ", ' ')
AssertEqual(t, "", res)

res = Trim("", ' ')
AssertEqual(t, "", res)
}

func Benchmark_Trim(b *testing.B) {
Expand Down