mansooor elaahi
mansooor elaahi

Reputation: 1

error: invalid byte sequence in UTF-8 after upgrading ruby 1.8.7 to ruby 1.9.2

I had my app running in ruby 1.8.7 and rails 3.0.11 ,I upgraded it with 1.9.2 ruby and rails 3.2.2. it has a utf convertor like this

@utf8_converter = Iconv.new('UTF-8//IGNORE', 'UTF-8')
......  
......
def utf8(untrusted_string)
valid_string = @utf8_converter.iconv(untrusted_string + ' ')[0..-2]
return valid_string

Unto my Understanding Iconv doesn't support ruby 1.9.2. how can make it run?

Thanks

Upvotes: 0

Views: 354

Answers (2)

Eugene
Eugene

Reputation: 4879

I believe this is should get you on the right track:

def utf8(untrusted_string) 
  valid_string = (untrusted_string + ' ').encode('utf-8')
  return valid_string
end

The @utf8_converter variable is no longer needed as Iconv is deprecated, so you can get away with just your utf8 method.

Upvotes: 1

nkm
nkm

Reputation: 5914

Ruby 1.9.2 does support Iconv, if you are using ruby through rvm, you should install it in the following way,

$ rvm pkg install iconv
$ rvm reinstall 1.9.2 --with-iconv-dir=$rvm_path/usr

Read more here

Upvotes: 0

Related Questions