by londons_explore · 2y ago · 0 comments
If you have invalid utf-8, go fix whatever code it is that is producing invalid utf-8...
And obviously you don't want to spend more time doing this than necessary.
Not all sequences of bytes are valid UTF-8. A UTF-8 decoder should be prepared for:
invalid bytes
an unexpected continuation byte
a non-continuation byte before the end of the character
the string ending before the end of the character (which can happen in simple string truncation)
an overlong encoding
a sequence that decodes to an invalid code point
https://en.wikipedia.org/wiki/UTF-8