starwing / luautf8

a utf-8 support module for Lua and LuaJIT.
MIT License
406 stars 67 forks source link

utf8.len() never return false when UTF8 has an invalid sequence #13

Closed cvuillemez closed 4 years ago

cvuillemez commented 6 years ago

Hi, I want to use utf8.len() on lua 5.1 to validate a UTF8 sequence but it does not do the job.

When I put a good sequence:

> s = '\207\180'
> len, inv = utf8.len(s)
> print(len, inv)
1       nil
> print(utf8.codepoint(s,1,-1))
1012

.. function works as expected, it prints the right codepoint and length, but when I put an invalid sequence:

> s = '\255\180'
> len, inv = utf8.len(s)
> print(len, inv)
2       nil
> print(utf8.codepoint(s,1,-1))
510     180

.. i t does not return the false value and the position of the first invalid byte, like explained here Or maybe this module does not implement utf8 support like LUA 5.3 ?

Thanks.

johnd0e commented 4 years ago

@starwing

Why have you closed this issue? Is it resolved?

starwing commented 4 years ago

Yes, I fixed at HEAD