Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: try to get jruby green by pinning jar-dependencies #3391

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ end
# Then re-run `bundle install`.
group :rdoc do
gem "rdoc", "6.10.0"
gem "jar-dependencies", "0.4.1" if RUBY_PLATFORM == "java" # https://github.com/jruby/jruby/issues/7262
end
21 changes: 19 additions & 2 deletions ext/java/nokogiri/XmlXpathContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ public class XmlXpathContext extends RubyObject
public IRubyObject
register_ns(IRubyObject prefix, IRubyObject uri)
{
nsContext.registerNamespace(prefix.asJavaString(), uri.asJavaString());
if (uri.isNil()) {
nsContext.deregisterNamespace(prefix.asJavaString());
} else {
nsContext.registerNamespace(prefix.asJavaString(), uri.asJavaString());
}
return this;
}

Expand All @@ -169,10 +173,23 @@ public class XmlXpathContext extends RubyObject
variableResolver = NokogiriXPathVariableResolver.create();
this.variableResolver = variableResolver;
}
variableResolver.registerVariable(name.asJavaString(), value.asJavaString());
if (value.isNil()) {
variableResolver.deregisterVariable(name.asJavaString());
} else {
variableResolver.registerVariable(name.asJavaString(), value.asJavaString());
}
return this;
}

@JRubyMethod(name = "node=")
public IRubyObject
set_node(ThreadContext context, IRubyObject rb_node)
{
this.context = (XmlNode) rb_node;
return rb_node;
}


private IRubyObject
node_set(ThreadContext context, String expr, IRubyObject handler)
{
Expand Down
6 changes: 6 additions & 0 deletions ext/java/nokogiri/internals/NokogiriNamespaceContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,10 @@ public final class NokogiriNamespaceContext implements NamespaceContext
register.put(prefix, uri);
}

public void
deregisterNamespace(String prefix)
{
if ("xmlns".equals(prefix)) { prefix = ""; }
register.remove(prefix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ public class NokogiriXPathVariableResolver implements XPathVariableResolver
{
variables.put(new QName(name), value);
}
public void
deregisterVariable(String name)
{
variables.remove(new QName(name));
}

}
10 changes: 5 additions & 5 deletions test/xml/test_xpath_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ module XML
xc = XPathContext.new(doc)

assert_raises(XPath::SyntaxError) do
xc.evaluate("//xmlns:child")
xc.evaluate("//foo:child")
end

xc.register_namespaces({ "xmlns" => "http://nokogiri.org/default" })
xc.register_namespaces({ "foo" => "http://nokogiri.org/default" })
assert_pattern do
xc.evaluate("//xmlns:child") => [
xc.evaluate("//foo:child") => [
{ name: "child", namespace: { href: "http://nokogiri.org/default" } }
]
end

xc.register_namespaces({ "xmlns" => nil })
xc.register_namespaces({ "foo" => nil })
assert_raises(XPath::SyntaxError) do
xc.evaluate("//xmlns:child")
xc.evaluate("//foo:child")
end
end

Expand Down
Loading