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

Frederick Cheung
2010-12-15T10:27:01Z

On Dec 14, 4:22 pm, 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
>
> In fact, strip() doesn''t works if the last printable character is
> accentuated.
> Surprisingly " écologie".strip works fine.
>
> I''ve tried to dig deeper in active_support multibyte source code
but
> didn''t found any solution.
>
> Any help ?
>
> --
> Posted viahttp://www.ruby-forum.com/.