Skip to content

Commit

Permalink
Fix for issue#489. Also adds a test of blank? to test/xml/test_node.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
yokolet committed Jul 8, 2011
1 parent b7a5050 commit 64da567
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ext/java/nokogiri/XmlNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,13 @@ public IRubyObject attribute_with_ns(ThreadContext context, IRubyObject name, IR

@JRubyMethod(name = "blank?")
public IRubyObject blank_p(ThreadContext context) {
String data = node.getTextContent();
if ("".equals(data.trim())) return context.getRuntime().getTrue();
// according to libxml doc,
// a node is blank if if it is a Text or CDATA node consisting of whitespace only
if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) {
String data = node.getTextContent();
if (data == null) return context.getRuntime().getTrue();
if ("".equals(data.trim())) return context.getRuntime().getTrue();
}
return context.getRuntime().getFalse();
}

Expand Down
5 changes: 5 additions & 0 deletions test/xml/test_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,11 @@ def awesome! ; end
assert_equal @xml, node_set.document
assert node_set.respond_to?(:awesome!)
end

def test_blank
doc = Nokogiri::XML('')
assert_equal false, doc.blank?
end
end
end
end

0 comments on commit 64da567

Please sign in to comment.