Ticket #130 (new defect)

Opened 5 months ago

Exception raised when searching documents with DocTypes

Reported by: ara_vartanian Owned by: why
Priority: major Milestone: 0.6
Component: lib/hpricot Version:
Keywords: Cc:

Description

Documents with doctypes seem to trigger an exception when searched. Here's an example:

text = <<END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
END
doc = Hpricot(text)
doc.search("*[text()*='anything']")

Problem seems to lie in this code in elements.rb:

    pred_procs =
      {'text()' => proc { |ele, *_| ele.inner_text.strip },
       '@'      => proc { |ele, attr, *_| ele.get_attribute(attr).to_s if ele.elem? }}

Hpricot::DocType#inner_text? returns nil. This simple declaration solves the problem, but maybe you guys will want to patch it up differently. I don't know what the contract of inner_text is:

class Hpricot::DocType
  def inner_text
    ''
  end
end

Note: See TracTickets for help on using tickets.