fix crash when string contains non ascii characters