Handle input strings with strange encodings

@mattgillooly