Consistent Encoding for iCal file import

596 views Asked by At

I'm trying to use the iCalendar gem to import some iCal files on a rails 4 site.

Sometimes the file is of type 'text/calendar;charset=utf-8' and sometimes its 'text/calendar; charset=UTF-8;'

I am retrieving it like this:

uri = URI.parse(url)
calendar = Net::HTTP.get_response(uri)
new_calendar = Icalendar.parse(calendar.body)

When its text/calendar;charset=utf-8 it works fine. but when its text/calendar; charset=UTF-8 encoded I get UTF codes in the string

SUMMARY:Tech Job Fair – City(ST) – Jul 1, 2015

ends up being

["Tech Job Fair \xE2\x80\x93 City(ST) \xE2\x80\x93 Jul 1", " 2015"]

Which is then saved to the database and that is undesirable.

Is the charset/content-type revealing the problem here or could it actually just be encoded wrong from the source?

How do I change my retrieval commands to strip those codes out effectively or tell it its a UTF string so it doesn't include them in the first place?

Update: it looks like some are text/calendar;charset=utf-8 and some are text/calendar;charset=UTF-8 and some are text/calendar; charset=UTF-8. Note the last one has a space between the two segments. Could this be causing an issue?

Update2: Opening up my three example iCal files in Notepad++ shows them encoded as "UTF-8 without BOM" in the menu.

0

There are 0 answers