Fix crash when non UTF-8 characters are used.