Re: UTF-8 String.strip bug (and several over methods)

Peter Vandenabeele
2010-12-16T17:00:11Z

Frederick Cheung wrote in post #968521:
> On Dec 14, 4:22pm, Bob Mundane
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:
>> Hello, with Rails 3.0.3
>>
>> "Caf Noir ".strip => "Caf noir"
>> but
>> "Caf ".strip => "Caf\303\251"
>
> While it may not look pretty this is accurate if you are using utf8 -
>  is 0xC3 0xA9 in UTF8, which is 0o303 0o251 in octal. I''m not sure
> why inspect is choosing to show the octal escape codes but you string
> does contain the correct bytes. (maybe some heuristic that tries to
> determine whether the string is utf8 and show be displayed as such or
> whether it just contains random binary gunk)
>
> Fred

I tried in 3 different versions of ruby and the way it is rendered in
irb
is indeed different (and is confusing):

ruby-1.8.7-p302 > "Caf\303\251"
 => "Caf\303\251"
...
ree-1.8.7-2010.02 > "Caf\303\251"
 => "Caf\303\251"
...
ruby-1.9.2-head >   "Caf\303\251"
 => "Café"


@Bob, are you sure you use UTF-8 encoding for your web page?

HTH,

Peter