Hi Perry,

I've run into such encoding issues under ruby 1.9.x and rails 3.x when
dealing with unknown/untrusted/bad non-utf8 data params that need to
be handled by the rails app as utf-8.

The fix I found (that works for the needs of my apps) was by following
a strategy outlined by Paul Battley (http://po-ru.com/diary/fixing-
invalid-utf-8-in-ruby-revisited/ ) using Iconv for forcing a string to
utf-8:

  ...
  UTF8_IC = Iconv.new('UTF-8//IGNORE', 'UTF-8')

  ...
  def force_utf8(v)
    return (v.is_a?(String)) ? UTF8_IC.iconv("#{v} ")[0..-2] : v
  end

  ...

and then adding a before_filter which modifies submitted params
strings forcing them to utf-8 before accessing/using those params in
the app.

(Maybe there's a better/simpler way since I last tested this issue?)

Jeff


On Sep 6, 11:03 am, Perry Smith <li...@ruby-forum.com> wrote:
> Yes, I understand Ruby's encodings.  That isn't my question.
>
> My question is what is a good consistent way to deal with the in Rails
> given that the input may be any language, you do not have control over
> the various source files in the gems, etc.
>
> i.e. since the rails files do not have the UTF-8 encoding tag, their
> defaults is whatever are the default is for my country.  But that
> setting may be different from the end user's browser's settings.  There
> are just all sorts of ways that different encodings can get into the
> mix.  Hasn't anyone else fought these wars besides me?
>
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to