Reputation: 22731
When I insert certain strings coming in from API calls into my db, they get cut off at certain characters. This is with ruby 1.8.7. I have everything set to utf8 app-wide and in MySQL. I typically don't have any problem entering utf8 content into the DB in other parts of the app.
It's supposed to be "El Soldado y La Muñeca". If I insert it into the db, only this makes it in: "11 El Soldado y La Mu".
>> name => "11 El Soldado y La Mu?eca(1).mp3" >> name[20..20] => "u" >> name[21..21] => "\361" >> name[22..22] => "e"
update
CORRECTION-- i was wrong, it's not coming from the api, it's coming from the file system.
the wrongly-encoded character is coming from inside the house!
new question: How can I get utf8 characters from File#path
Upvotes: 0
Views: 255
Reputation: 434675
You are somehow getting a Latin-1 (AKA ISO-8859-1) ñ
rather than a UTF-8 ñ
. In Latin-1 the ñ
is 361 in octal (hence your single byte "\361"
). In UTF-8 that lower case tilde-n should be \303\261
(i.e. bytes 0303 and 0261 in octal or 0xc3 and 0xb1 in hex).
You might have to start playing with Iconv in the Ruby side to make sure you get everything in UTF-8.
Upvotes: 2