Incorrect documentation on utf8.len - returns nil for invalid byte sequences and not false

The documentation for utf8.len (utf8 | Documentation - Roblox Creator Hub) says that it returns the number of codepoints on a string if succesful, and if not, then false as well as the position of the first invalid byte sequence, however, it appears to return nil, not false along with the position of the invalid byte sequence if it finds one:

Example:

local a = string.char(233, 173, 148) -- some random chinese character
local b = string.char(233, 173) -- an invalid character

print(utf8.len(a))
print(utf8.len(b))

The first print statement results in 1, the string contains all valid byte sequences. The second print statement results in nil, 1 and not false, 1.

5 Likes