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

🐛 utils.TrimBytes wrong result if it should return a empty bytes #1778

Closed
fufuok opened this issue Feb 15, 2022 · 0 comments · Fixed by #1779
Closed

🐛 utils.TrimBytes wrong result if it should return a empty bytes #1778

fufuok opened this issue Feb 15, 2022 · 0 comments · Fixed by #1779

Comments

@fufuok
Copy link
Contributor

fufuok commented Feb 15, 2022

Fiber version

v2.27.0

Issue description

follow-up questions: #1774

utils.TrimBytes([]byte(" "), ' ') got []byte(" ") instead of []byte("")

Code snippet

package main_test

import (
	"bytes"
	"testing"

	"github.com/gofiber/fiber/v2/utils"
)

func TestShouldBeEmptyBytes(t *testing.T) {
	res := bytes.Trim([]byte(" "), " ")
	utils.AssertEqual(t, 0, len(res)) // this is right

	res = bytes.Trim([]byte("  "), " ")
	utils.AssertEqual(t, 0, len(res)) // this is right

	res = utils.TrimBytes([]byte(" "), ' ')
	utils.AssertEqual(t, 0, len(res)) // this is wrong, result is 1

	res = utils.TrimBytes([]byte("  "), ' ')
	utils.AssertEqual(t, 0, len(res)) // this is wrong, result is 1

	res = utils.TrimBytes([]byte(""), ' ')
	utils.AssertEqual(t, 0, len(res))
}
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 a pull request may close this issue.

1 participant