2

I'm writing a Ruby program to fetch some code from the net and sometimes it had this error:

Error incomplete multibyte character.

I'm trying to escape() the string using pg.

How can I handle this error? How can I convert the string to a valid UTF8 string?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
wezzy
  • 5,897
  • 3
  • 31
  • 42

2 Answers2

1

To convert between encodings, try ruby's Iconv class. It's in the standard library.

Mike Sherrill 'Cat Recall'
  • 91,602
  • 17
  • 122
  • 185
  • Note that iconv was deprecated in Ruby 1.9; see http://stackoverflow.com/questions/8148762/iconv-deprecation-warning-with-ruby-1-9-3 – Ben Feb 18 '13 at 15:57
0

I'm coming in this discussion as I had the same issue. Some tried something strange with my application and I received the following exception email report:

PG::Error occurred in slides#show:

incomplete multibyte character

activerecord (3.2.11) lib/active_record/connection_adapters/postgresql_adapter.rb:472:in `escape_string'


Request:


Session:

  • session id: nil
  • data: {}

So how to handle this case ?

ZedTuX
  • 2,859
  • 3
  • 28
  • 58