Check for invalid UTF-8 encoded strings in cutsets #252
Comments
@dsnet Is golint the right place for this check? AFAIK, golint is about style, not correctness. I'm currently trying to decide between sending a PR to golint and adding the check to my own |
I'm actually not sure. You are right that this is an issue about correctness, so it doesn't quite fit as a lint check either. According to golang/go#17780, the criterion for a vet check is: correctness, frequency, and precision. When I looked over a large number of Go code inside Google, this mishap only occurred a few dozen times, so it probably doesn't hit the frequency requirements. If you want to add it to |
Inspired by golang/lint#252 Idea-By: Joe Tsai <joetsai@digital-static.net>
I've added the check to staticcheck. Running it against my corpus also yielded a very low number of results, so most likely not suitable for vet. |
I'm going to close this issue since the feature request fits neither |
Inspired by golang/lint#252 Idea-By: Joe Tsai <joetsai@digital-static.net>
The
(strings|bytes).(IndexAny|LastIndexAny|ContainsAny|Trim|TrimLeft|TrimRight)
functions take an argument for a set of UTF-8 encoded characters to match on. In production code, I have seen incorrect uses of these functions where the user treatschars
as simply a list of bytes, rather UTF-8 encoded characters.Most likely, any invalid
chars
input is due to user error. The following is probably not what a user expects:This currently prints
test
, while the user expectation is probably\x80test
.The text was updated successfully, but these errors were encountered: