Open sfgeorge opened 10 years ago
Updated test cases, to zero-in on the specific problem. Also, confirmed that this is occurring on both CRuby and JRuby.
Stepping through this with a debugger, I've found that this issue occurs when embed
encounters this line in nokogiri 1.6.1.
Stepping through this with a debugger, I've found that this issue occurs when
embed
encounters this line in nokogiri 1.6.1.
...also meant to mention specifically what's happening on this line. Nokogiri is making a few direct modifications to node
rather than merely "appending" it into another document:
This can be seen in a debugger session on CRuby:
Breakpoint 1 at /Users/sgeorge/.rvm/gems/ruby-1.9.3-p545/gems/nokogiri-1.6.1/lib/nokogiri/xml/node.rb:948
[943, 952] in /Users/sgeorge/.rvm/gems/ruby-1.9.3-p545/gems/nokogiri-1.6.1/lib/nokogiri/xml/node.rb
943 def inspect_attributes
944 [:name, :namespace, :attribute_nodes, :children]
945 end
946
947 def add_child_node_and_reparent_attrs node
=> 948 add_child_node node
949 node.attribute_nodes.find_all { |a| a.name =~ /:/ }.each do |attr_node|
950 attr_node.remove
951 node[attr_node.name] = attr_node.value
952 end
(rdb:1) node.children.map(&:object_id)
[70348856393920]
(rdb:1) node.namespace
#<Nokogiri::XML::Namespace:0x3ffb5e988980 href="http://www.w3.org/2001/10/synthesis">
And afterwards:
(rdb:1) n
/Users/sgeorge/.rvm/gems/ruby-1.9.3-p545/gems/nokogiri-1.6.1/lib/nokogiri/xml/node.rb:949
node.attribute_nodes.find_all { |a| a.name =~ /:/ }.each do |attr_node|
[944, 953] in /Users/sgeorge/.rvm/gems/ruby-1.9.3-p545/gems/nokogiri-1.6.1/lib/nokogiri/xml/node.rb
944 [:name, :namespace, :attribute_nodes, :children]
945 end
946
947 def add_child_node_and_reparent_attrs node
948 add_child_node node
=> 949 node.attribute_nodes.find_all { |a| a.name =~ /:/ }.each do |attr_node|
950 attr_node.remove
951 node[attr_node.name] = attr_node.value
952 end
953 end
(rdb:1) n
(rdb:1) node.children.map(&:object_id)
[70348856600400]
(rdb:1) node.namespace
#<Nokogiri::XML::Namespace:0x3ffb5e9b7e88 prefix="default" href="http://www.w3.org/2001/10/synthesis">
When
ssml_doc.embed(original_doc)
is used to embed one document within another, the original document is left modified unexpectedly. This is exhibited in the following tests: https://github.com/sfgeorge/ruby_speech/compare/539d2cce...bug;destructive-embedHere's an example using ruby_speech 2.3.1...