You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not clear to me why we're using a namespace cache in the JRuby implementation. It is causing problems in edge cases like #1247 that I think would be better solved by looking up the node's parent chain for an identical namespace definition a) when it is added, and b) when the node is reparented.
This is what we do in the CRuby implementation. It's more complicated (and likely still has some bugs) but it is obviously more correct in these edge cases.
it"handles multiple instances of a namespace definition"do# this describes behavior that is broken in JRuby related to the namespace cache and should be fixeddoc=Nokogiri::XML::Document.parse("<root>")child1=doc.create_element("a","xmlns:foo"=>"http://nokogiri.org/ns/foo")assert_equal(1,child1.namespace_definitions.length)child1.namespace_definitions.first.tapdo |ns|
assert_equal("foo",ns.prefix)assert_equal("http://nokogiri.org/ns/foo",ns.href)endchild2=doc.create_element("b","xmlns:foo"=>"http://nokogiri.org/ns/foo")pending_if("broken in JRuby related to the namespace cache and should be fixed",Nokogiri.jruby?)doassert_equal(1,child2.namespace_definitions.length)child2.namespace_definitions.first.tapdo |ns|
assert_equal("foo",ns.prefix)assert_equal("http://nokogiri.org/ns/foo",ns.href)endendend
In summary, the second node does not have a namespace definition in the JRuby implementation. This is clearly wrong.
A partial fix would be to reimplement Node#namespace_definitions to look at the attributes for a namespace definition:
@JRubyMethodpublicRubyArray<?>
namespace_definitions(ThreadContextcontext)
{
// TODO: I think this implementation would be better but there are edge casesRubyArray<?> nsdefs = RubyArray.newArray(context.getRuntime());
NamedNodeMapattrs = node.getAttributes();
for (intj = 0 ; j < attrs.getLength() ; j++) {
Attrattr = (Attr)attrs.item(j);
if ("http://www.w3.org/2000/xmlns/" == attr.getNamespaceURI()) {
nsdefs.append(XmlNamespace.createFromAttr(context.getRuntime(), attr));
}
}
returnnsdefs;
}
but we also need to then implement something like xml_node.c:relink_namespace in order to make this match the CRuby behavior.
The text was updated successfully, but these errors were encountered:
Please describe the bug
It's not clear to me why we're using a namespace cache in the JRuby implementation. It is causing problems in edge cases like #1247 that I think would be better solved by looking up the node's parent chain for an identical namespace definition a) when it is added, and b) when the node is reparented.
This is what we do in the CRuby implementation. It's more complicated (and likely still has some bugs) but it is obviously more correct in these edge cases.
An example taken from #1247 is:
In summary, the second node does not have a namespace definition in the JRuby implementation. This is clearly wrong.
A partial fix would be to reimplement
Node#namespace_definitions
to look at the attributes for a namespace definition:but we also need to then implement something like
xml_node.c:relink_namespace
in order to make this match the CRuby behavior.The text was updated successfully, but these errors were encountered: