Merge pull request #3594 from theduke/unicode-validate-overlong
validateUtf8: catch overlong ascii
This commit is contained in:
commit
fbe6695a52
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