-
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
strings,bytes: improve doc of Split* functions for the empty string case #19726
Comments
CL https://golang.org/cl/38690 mentions this issue. |
I've created a CL addressing this issue by changing the behavior of the Split func to always return a |
The functions have behaved as they do since before the Go 1 release. I think we would need a strong reason to change that behavior, and I don't see that strong reason here. I think we should change the documentation instead. |
I think you should not think the go's behavior as same as perl. In javascript, |
What would be a good message to document it? Something like
seems too verbose to explain such an obscure feature. |
@ammario That's because it is obscure that it must be documented. |
CL https://golang.org/cl/44950 mentions this issue. |
In go 1.8 the behaviour of
strings.Split{,N,After,AfterN}
functions is not explicitly documented for the special case of splitting the empty string""
. The functions return a slice with a single element which is the empty string.The problem is that the Go behaviour is not the same as in other programming languages with functions with a similar name where for the same input the result is a zero-length array.
In Go (playground):
In Perl 5 the result is a zero-length list:
This leads to wrong expectations from users of the functions (especially when porting code from other languages) and may lead to security issues such as incorrect input validation or deny of service.
The documentation should be improved by documenting specially this corner case.
The text was updated successfully, but these errors were encountered: