Handle invalid encodings when calling String#gsub and String#gsub!