I am pulling out some RSS feeds from YouTube that have invalid UTF8. I can create a similar ruby string using
bad_utf8 = "\u{61B36}"
bad_utf8.encoding
bad_utf8.valid_encoding?
Ruby considers this to be valid UTF-8 encoding, and I'm sure it is not.
When you talk to Mysql, I get this error
require 'mysql2'
client = Mysql2::Client.new(:host => "localhost", :username => "root")
client.query("use test");
bad_utf8 = "\u{61B36}"
client.query("INSERT INTO utf8 VALUES ('#{moo}')")
How can I detect or fix these invalid encoding types before sending them to MySQL?
source
share