validateUtf8: catch overlong ascii
Make unicode.validateUtf8() check for overlong ascii representations, which are 2 bytes long and start with c0 or c1.
This commit is contained in:
parent
eaed36092c
commit
25b605a3a2
1 changed files with 1 additions and 0 deletions
|
|
@ -114,6 +114,7 @@ proc validateUtf8*(s: string): int =
|
||||||
if ord(s[i]) <=% 127:
|
if ord(s[i]) <=% 127:
|
||||||
inc(i)
|
inc(i)
|
||||||
elif ord(s[i]) shr 5 == 0b110:
|
elif ord(s[i]) shr 5 == 0b110:
|
||||||
|
if ord(s[i]) < 0xc2: return i # Catch overlong ascii representations.
|
||||||
if i+1 < L and ord(s[i+1]) shr 6 == 0b10: inc(i, 2)
|
if i+1 < L and ord(s[i+1]) shr 6 == 0b10: inc(i, 2)
|
||||||
else: return i
|
else: return i
|
||||||
elif ord(s[i]) shr 4 == 0b1110:
|
elif ord(s[i]) shr 4 == 0b1110:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue