mirror of https://github.com/gofiber/fiber.git
fix: `utils.Trim` should trim all string content (#1775)
* fix: `utils.Trim` should trim all string content * add empty string input * better fixpull/1779/head
parent
937713e41e
commit
391ae594d8
|
@ -43,7 +43,7 @@ func Trim(s string, cutset byte) string {
|
|||
break
|
||||
}
|
||||
}
|
||||
for ; i < j; j-- {
|
||||
for ; i <= j; j-- {
|
||||
if s[j] != cutset {
|
||||
break
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue