-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
bytes: ReplaceAll returns nil slice when empty slice is given #46415
Comments
Can I ask why you want them to be equally nil or not nil? As far as I know, that's not a guarantee of any of Go's APIs by default. |
The inconsistent type of slice (empty slice or nil slice) looks confusing. To me: Empty slice in, empty slice out. Nil slice in, nil slice out. |
FWIW, I think generally the pattern here is to check length instead of nil-ness. The length of a nil slice is also zero. |
The bytes package makes no promise to preserve the |
Please fix this issue. Using bytes.ReplaceAll corrupts empty slices when they are used as arguments of database queries. Currently additional checks are required for special cases of empty slices and a lot of unnecessary debugging. |
The documentation clearly says "ReplaceAll returns a copy of the slice..." If the slice is empty it should return the empty slice as it was exactly before without any changes. |
The |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
What did you expect to see?
the call of
bytes.ReplaceAll
on an empty slice should also return an empty slice. However, it returns nilWhat did you see instead?
The text was updated successfully, but these errors were encountered: