html2haml - Invalid UTF-8 character "\xE7"

867 views
Skip to first unread message

José Mota

unread,
Nov 22, 2010, 7:06:50 AM11/22/10
to Haml
It seems something is wrong with UTF8 encoded files being interpreted
in Haml. A basic html2haml command is throwing me ` Invalid UTF-8
character "\xE7" `.
Am I missing something or has it happened with more than just me?

Nathan Weizenbaum

unread,
Nov 22, 2010, 4:35:06 PM11/22/10
to ha...@googlegroups.com
What Ruby version are you using? Chances are your file is not actually UTF-8 encoded, and your OS isn't properly telling Ruby what the encoding is (e.g. by setting the locale to something appropriate). What happens if you run IRB and do Encoding.default_external?


--
You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.


José Mota

unread,
Nov 22, 2010, 4:53:30 PM11/22/10
to Haml
Sorry I have not provided enough info.
* Ruby version: 1.9.2p0
* > Encoding.default_external
=> #<Encoding:UTF-8>
* Sys: Mac OS 10.6.5

Thanks for helping on this, Nathan. I've tried the IRC channels,
googlin' for it but got zero response...

Nathan Weizenbaum

unread,
Nov 22, 2010, 4:57:15 PM11/22/10
to ha...@googlegroups.com
It seems likely that the file is actually in a non-UTF-8 encoding. How to fix this depends on your editor, and I'm not familiar with the details of most of them... presumably there would be some configuration option somewhere that you could set for what encoding to use.

José Mota

unread,
Nov 22, 2010, 5:31:18 PM11/22/10
to Haml
I'm using Vim. I've checked the encoding, it says utf-8. I'll try
Textmate and see if there's something over there.

José Mota

unread,
Nov 22, 2010, 5:41:36 PM11/22/10
to Haml
Nathan, I've set Vim's fileencoding and encoding to utf-8. Now I'm
getting another kind of error:

> Encoding::CompatibilityError at /
> incompatible character encodings: UTF-8 and ASCII-8BIT

Now it has something to do with the Ruby Encoding module. Do you have
any idea of what might be?

Nathan Weizenbaum

unread,
Nov 22, 2010, 5:46:23 PM11/22/10
to ha...@googlegroups.com
Hmm, that's a strange error to see. That suggests that somewhere you have a UTF-8 encoded string, and something is trying to force it into an ASCII-8BIT string. What does Encoding.default_internal return in IRB?

José Mota

unread,
Nov 22, 2010, 5:50:34 PM11/22/10
to Haml
> What does Encoding.default_internal return in IRB?
It returns nil.

Nathan Weizenbaum

unread,
Nov 22, 2010, 5:59:47 PM11/22/10
to ha...@googlegroups.com
Weird. What's the full backtrace of the error?

On Mon, Nov 22, 2010 at 2:50 PM, José Mota <josemota.net@gmail.com> wrote:
> What does Encoding.default_internal return in IRB?
   It returns nil.

--

José Mota

unread,
Nov 22, 2010, 6:01:25 PM11/22/10
to Haml
Thank you for taking your time on this. Here's the full trace:

Encoding::CompatibilityError - incompatible character encodings: UTF-8
and ASCII-8BIT:
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:323:in `block in flush_merged_text'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:320:in `each'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:320:in `flush_merged_text'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:809:in `render_tag'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:214:in `process_line'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:178:in `precompile'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
engine.rb:121:in `initialize'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/tilt.rb:444:in `new'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/tilt.rb:444:in `prepare'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/tilt.rb:124:in `initialize'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:370:in `new'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:370:in `block in compile_template'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/tilt.rb:327:in `fetch'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:358:in `compile_template'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:342:in `render'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:311:in `haml'
rb.rb:6:in `block in <main>'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:865:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:865:in `block in route'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:521:in `instance_eval'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:521:in `route_eval'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:500:in `block (2 levels) in route!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:497:in `catch'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:497:in `block in route!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:476:in `each'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:476:in `route!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:601:in `dispatch!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:411:in `block in call!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:566:in `instance_eval'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:566:in `block in invoke'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:566:in `catch'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:566:in `invoke'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:411:in `call!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:399:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
showexceptions.rb:24:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
methodoverride.rb:24:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
commonlogger.rb:18:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:979:in `block in call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:1005:in `synchronize'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:979:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
content_length.rb:13:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
chunked.rb:15:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
handler/mongrel.rb:67:in `process'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/mongrel-1.2.0.pre2/lib/
mongrel.rb:165:in `block in process_client'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/mongrel-1.2.0.pre2/lib/
mongrel.rb:164:in `each'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/mongrel-1.2.0.pre2/lib/
mongrel.rb:164:in `process_client'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/mongrel-1.2.0.pre2/lib/
mongrel.rb:291:in `block (2 levels) in run'
Encoding::CompatibilityError: incompatible character encodings: UTF-8
and ASCII-8BIT
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:323:in `block in flush_merged_text'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:320:in `each'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:320:in `flush_merged_text'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:809:in `render_tag'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:214:in `process_line'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
precompiler.rb:178:in `precompile'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.23/lib/haml/
engine.rb:121:in `initialize'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/tilt.rb:444:in `new'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/tilt.rb:444:in `prepare'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/tilt.rb:124:in `initialize'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:370:in `new'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:370:in `block in compile_template'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/tilt.rb:327:in `fetch'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:358:in `compile_template'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:342:in `render'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:311:in `haml'
rb.rb:6:in `block in <main>'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:865:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:865:in `block in route'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:521:in `instance_eval'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:521:in `route_eval'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:500:in `block (2 levels) in route!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:497:in `catch'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:497:in `block in route!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:476:in `each'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:476:in `route!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:601:in `dispatch!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:411:in `block in call!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:566:in `instance_eval'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:566:in `block in invoke'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:566:in `catch'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:566:in `invoke'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:411:in `call!'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:399:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
showexceptions.rb:24:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
methodoverride.rb:24:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
commonlogger.rb:18:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:979:in `block in call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:1005:in `synchronize'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/sinatra-1.0/lib/
sinatra/base.rb:979:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
content_length.rb:13:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
chunked.rb:15:in `call'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/rack-1.2.1/lib/rack/
handler/mongrel.rb:67:in `process'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/mongrel-1.2.0.pre2/lib/
mongrel.rb:165:in `block in process_client'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/mongrel-1.2.0.pre2/lib/
mongrel.rb:164:in `each'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/mongrel-1.2.0.pre2/lib/
mongrel.rb:164:in `process_client'
/Users/josemota/.rvm/gems/ruby-1.9.2-head/gems/mongrel-1.2.0.pre2/lib/
mongrel.rb:291:in `block (2 levels) in run'
127.0.0.1 - - [22/Nov/2010 23:00:30] "GET / HTTP/1.1" 500 130507
0.2253
127.0.0.1 - - [22/Nov/2010 23:00:30] "GET /__sinatra__/500.png HTTP/
1.1" 304 - 0.0006
127.0.0.1 - - [22/Nov/2010 23:00:31] "GET /favicon.ico HTTP/1.1" 404
420 0.0007

José Mota

unread,
Nov 22, 2010, 6:11:34 PM11/22/10
to Haml
Nathan, I've done it. I reviewed my file again, it is now working.
Rewriting it with the correct encodings, reloading, correcting all the
\xYZ characters and rewriting it again worked.

The important thing about this is: in Textmate it was working. For the
Vim lovers:
* set fileencoding=utf-8
* set encoding=utf-8
* remove UTF-8 special characters and write normal text.
* if an HTML file, don't forget to specify the content encoding to
utf-8 too.

Thank you for your help, you nailed it.

Nathan Weizenbaum

unread,
Nov 22, 2010, 6:17:04 PM11/22/10
to ha...@googlegroups.com
I thought you said this was in html2haml. If this is a normal Haml file, try adding "-# encoding: utf-8" to the top.


--

José Mota

unread,
Nov 22, 2010, 6:19:14 PM11/22/10
to ha...@googlegroups.com
Well, actually it was both the html2haml and the render, so I guessed it'd be an Haml::Engine issue. It's fine now, tho. Thank you very much, Nathan.
Reply all
Reply to author
Forward
0 new messages