Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix #617: Nokogiri::XML::Reader#outer_xml is broken in JRuby

  • Loading branch information...
commit 9fd591470596d7872cc1c5827df80e438e70fa32 1 parent 993d41b
@calavera calavera authored
Showing with 37 additions and 2 deletions.
  1. +8 −2 ext/java/nokogiri/XmlReader.java
  2. +29 −0 test/test_reader.rb
View
10 ext/java/nokogiri/XmlReader.java
@@ -229,7 +229,10 @@ private String getInnerXml(ArrayDeque<ReaderNode> nodeQueue, ReaderNode current)
StringBuffer sb = new StringBuffer();
int currentDepth = (Integer)current.depth;
for (ReaderNode node : nodeQueue) {
- if (((Integer)node.depth) > currentDepth) sb.append(node.getString());
+ if (((Integer)node.depth) > currentDepth) {
+ sb.append(node.getString());
+ break;
+ }
}
return new String(sb);
}
@@ -244,7 +247,10 @@ private String getOuterXml(ArrayDeque<ReaderNode> nodeQueue, ReaderNode current)
StringBuffer sb = new StringBuffer();
int initialDepth = (Integer)current.depth - 1;
for (ReaderNode node : nodeQueue) {
- if (((Integer)node.depth) > initialDepth) sb.append(node.getString());
+ if (((Integer)node.depth) > initialDepth) {
+ sb.append(node.getString());
+ break;
+ }
}
return new String(sb);
}
View
29 test/test_reader.rb
@@ -422,4 +422,33 @@ def test_large_document_smoke_test
end
end
+ def test_correct_outer_html_inclusion
+ xml = Nokogiri::XML::Reader.from_io(StringIO.new(<<-eoxml))
+ <root-element>
+ <children>
+ <child n="1">
+ <field>child-1</field>
+ </child>
+ <child n="1">
+ <field>child-2</field>
+ </child>
+ </children>
+ </root-element>
+ eoxml
+
+ nodelengths = []
+ has_child2 = []
+
+ xml.each do |node|
+ if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT and node.name == "child"
+ nodelengths << node.outer_xml.length
+ has_child2 << !!(node.outer_xml =~ /child-2/)
+ end
+ end
+
+ assert_equal(nodelengths[0], nodelengths[1])
+ assert(has_child2[1])
+ assert(!has_child2[0])
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.