fix #8341, parser hang on EOF during character byte sequence

Backport of cfd60f1