Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allowing insertion of processing instructions via #add_previous_sibli…

…ng. Closes #630.

See related commit c5e4372 which broke this functionality.
  • Loading branch information...
commit 0ea3e76f8cc8857a1a146810826d936fdd18f601 1 parent b70048b
@flavorjones flavorjones authored
Showing with 9 additions and 1 deletion.
  1. +1 −1  lib/nokogiri/xml/node.rb
  2. +8 −0 test/xml/test_unparented_node.rb
View
2  lib/nokogiri/xml/node.rb
@@ -297,7 +297,7 @@ def << node_or_tags
#
# Also see related method +before+.
def add_previous_sibling node_or_tags
- raise ArgumentError.new("A document may not have multiple root nodes.") if parent.is_a?(XML::Document)
+ raise ArgumentError.new("A document may not have multiple root nodes.") if parent.is_a?(XML::Document) && !node_or_tags.is_a?(XML::ProcessingInstruction)
node_or_tags = coerce(node_or_tags)
if node_or_tags.is_a?(XML::NodeSet)
View
8 test/xml/test_unparented_node.rb
@@ -248,6 +248,14 @@ def test_add_previous_sibling_to_root_raises_exception
end
end
+ def test_add_pi_as_previous_sibling_to_root_is_ok
+ doc = Nokogiri::XML "<root>foo</root>"
+ pi = Nokogiri::XML::ProcessingInstruction.new(doc, "xml-stylesheet", %q{type="text/xsl" href="foo.xsl"})
+ doc.root.add_previous_sibling pi
+ expected_doc = %Q{<?xml version="1.0"?>\n<?xml-stylesheet type="text/xsl" href="foo.xsl"?>\n<root>foo</root>\n}
+ assert_equal expected_doc, doc.to_xml
+ end
+
def test_find_by_css_with_tilde_eql
xml = Nokogiri::XML.parse(<<-eoxml)
<root>
Please sign in to comment.
Something went wrong with that request. Please try again.