# Bug in SGML parser

**URL:** <https://www.ruby-forum.com/t/bug-in-sgml-parser/78606>\
**Category:** Ruby\
**Created:** [December 7, 2006, 7:15am UTC](https://www.ruby-forum.com/t/bug-in-sgml-parser/78606 "2006-12-07T07:15:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 7, 2006, 7:15am UTC](https://www.ruby-forum.com/t/bug-in-sgml-parser/78606/1 "2006-12-07T07:15:37Z")

</div>

The sgml parser  
/usr/local/lib/ruby/gems/1.8/gems/htmltools-1.10/lib/html/sgml-parser.rb  
does not correctly handle character references. Yahoo sometimes  
generates a character reference that looks like “’”. Firefox  
displays this as a single quote. sgml-parser.rb raises an exception.

rescued: invalid value for Integer: “039” at Wed Dec 06 18:02:56 PST  
2006  
/usr/local/lib/ruby/gems/1.8/gems/htmltools-1.10/lib/html/sgml-parser.rb:335:in  
`Integer'/usr/local/lib/ruby/gems/1.8/gems/htmltools-1.10/lib/html/sgml-parser.rb:335:in`handle\_charref’/usr/local/lib/ruby/gems/1.8/gems/htmltools-1.10/lib/html/sgml-parser.rb:159:in  
`goahead'/usr/local/lib/ruby/gems/1.8/gems/htmltools-1.10/lib/html/sgml-parser.rb:88:in`feed’/usr/local/lib/ruby/gems/1.8/gems/rubyful\_soup-1.0.4/lib/rubyful\_soup.rb:547:in  
`feed’/usr/local/lib/ruby/gems/1.8/gems/rubyful\_soup-1.0.4/lib/rubyful\_soup.rb

Possible fix: In handle\_charref, strip leading zeroes from ‘name’  
prior to calling ‘Integer’.
