# Utf-8 htmlentities,decode keeps switching to ascii-8bit

**URL:** <https://www.ruby-forum.com/t/utf-8-htmlentities-decode-keeps-switching-to-ascii-8bit/186095>\
**Category:** Rails\
**Created:** [March 31, 2010, 3:13pm UTC](https://www.ruby-forum.com/t/utf-8-htmlentities-decode-keeps-switching-to-ascii-8bit/186095 "2010-03-31T15:13:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![noxx000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b77776/32.png) [@noxx000](https://www.ruby-forum.com/u/noxx000)\
**Post date:** [March 31, 2010, 3:13pm UTC](https://www.ruby-forum.com/t/utf-8-htmlentities-decode-keeps-switching-to-ascii-8bit/186095/1 "2010-03-31T15:13:01Z")

</div>

Hi there,  
it’s not really rubyonrails but because it fits into the web-development  
I think I’m in the right forum.

I’m trying to decode a string I read from an online xml-file and compare  
it to another, locally stored one.

The locally stored string is:  
p localstring #=\> “~St0rmâ‚¬lite~”  
p localstring.encoding #=\> #Encoding:UTF-8

The xml-file is saved as utf-8 and was read via HPricot.  
p remotestring #=\> “~St0rm€lite~”  
p remotestring.encoding #=\> #Encoding:UTF-8

Now I want to decode the remote string. To do this I’m using  
htmlentities4.2.0 installed via gem, however it breaks the string  
completely:  
require ‘htmlentities’  
htmldecoder = HTMLEntities.new  
p htmldecoder.decode(remotestring) #=\> “~St0rm\xE2\x82\xAClite~”  
p htmldecoder.decode(remotestring).encoding #=\> #Encoding:ASCII-8BIT

I’m trying to fix this the past 3-4 days but I didn’t find a solution.  
I tried to convert it again to utf-8 but this make the string getting  
even worser.  
Also converting the local-string to ASCII-8BIT fails.

I looked up my system configuration:  
My shell is running as UTF-8, also I installed ‘locales’:  
p Locale.current #=\> [#\<Locale::Tag::Posix: en\_US.UTF-8\>]

Is there any other settings I need to look up and configure? If I try  
the script on another computer I get the right results but here it keeps  
switching to ASCII-8BIT.  
My Ruby version is 1.9

I would be happy if someone could help me.
