Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

HTML::Node.parse has problems with CDATA

#1069

actionpack's HTML::Node.parse improperly handles some CDATA tags. It always raises when given an unclosed CDATA, and can't handle CDATA containing another CDATA open tag. For example:


# Can parse unclosed HTML tag with strict=false...
>> HTML::Node.parse(nil,0,0,'<foo', false)
=> #<HTML::Tag:0xb6510c28 @children=[], @closing=nil, @parent=nil, @position=0, @line=0, @attributes={}, @name="foo">


# ... but fails to parse unclosed CDATA tag
>> HTML::Node.parse(nil,0,0,'<![CDATA[', false)
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.gsub
        from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/vendor/html-scanner/html/node.rb:154:in `parse'
        from (irb):37

# Can't handle the string "<![CDATA[" inside a CDATA tag
>> HTML::Node.parse(nil,0,0,'<![CDATA[<![CDATA[]]>').content
=> ""

# to_s is missing a ']' in the ]]> close tag
>> HTML::Node.parse(nil,0,0,'<![CDATA[foo bar]]>').to_s
=> "<![CDATA[foo bar]>"

Patch for these issues is attached.

Reported by Matt Hanlon · September 18th, 2008 @ 06:21 PM

State: duplicate
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to duplicate

    October 24th, 2008 @ 03:24 AM