Skip to content

Commit

Permalink
ci: try to get jruby green by pinning jar-dependencies (#3391)
Browse files Browse the repository at this point in the history
**What problem is this PR intended to solve?**

Workaround recommended in jruby/jruby#7262
  • Loading branch information
flavorjones authored Dec 24, 2024
2 parents 5402925 + 24180fb commit ed07431
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
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

0 comments on commit ed07431

Please sign in to comment.