2

mp3 のタグを sqlite データベースに保存しようとすると、次のエラーが発生します。

 
SQL (0.3ms)  INSERT INTO "songs" ("album", "artist", "created_at", "length", "path", "store_id", "title", "track_number", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)  [["album", "\xFF\xFE2\x001\x00"], ["artist", "\xFF\xFEa\x00d\x00e\x00l\x00e\x00"], ["created_at", Tue, 24 Jul 2012 03:34:03 UTC +00:00], ["length", 15], ["path", "/audios/music/Adele - Discography (Complete) [2008 - 2011]/Adele - 21 [2011] + Bonus Tracks/01. Adele - Rolling in the Deep.mp3"], ["store_id", 3], ["title", "\xFF\xFEr\x00o\x00l\x00l\x00i\x00n\x00g\x00 \x00i\x00n\x00 \x00t\x00h\x00e\x00 \x00d\x00e\x00e\x00p\x00"], ["track_number", "01"], ["updated_at", Tue, 24 Jul 2012 03:34:03 UTC +00:00]]
Encoding::UndefinedConversionError: "\xFF" from ASCII-8BIT to UTF-8: INSERT INTO "songs" ("album", "artist", "created_at", "length", "path", "store_id", "title", "track_number", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
   (0.2ms)  rollback transaction
ActiveRecord::StatementInvalid: Encoding::UndefinedConversionError: "\xFF" from ASCII-8BIT to UTF-8: INSERT INTO "songs" ("album", "artist", "created_at", "length", "path", "store_id", "title", "track_number", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
 

入力を削除またはサニタイズするにはどうすればよいですか?

4

1 に答える 1