Skip to content

Commit

Permalink
Always use XPathFunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanhefner committed Aug 30, 2022
1 parent 7e6e77d commit 25e6ac7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ext/java/nokogiri/XmlXpathContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class XmlXpathContext extends RubyObject
{
String query = rbQuery.convertToString().asJavaString();

if (!handler.isNil() && !isContainsPrefix(query)) {
if (!isContainsPrefix(query)) {
//
// The user has passed in a handler, but isn't using the `nokogiri:` prefix as
// instructed in JRuby land, so let's try to be clever and rewrite the query, inserting
Expand All @@ -131,9 +131,10 @@ public class XmlXpathContext extends RubyObject
jchar = xpathFunctionCalls.end();
}

if (jchar < query.length() - 1) {
if (jchar < query.length()) {
namespacedQuery.append(query.subSequence(jchar, query.length()));
}

query = namespacedQuery.toString();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/nokogiri/xml/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def extract_params(params) # :nodoc:
![Hash, String, Symbol].include?(param.class)
end
params -= [handler] if handler
handler = XPathFunctions.new(handler) if handler
handler = XPathFunctions.wrap(handler)

hashes = []
while Hash === params.last || params.last.nil?
Expand Down
9 changes: 9 additions & 0 deletions lib/nokogiri/xml/xpath_functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
module Nokogiri
module XML
class XPathFunctions < SimpleDelegator
class << self
def wrap(handler)
if handler.nil?
@wrap_nil ||= new(Object.new)
else
new(handler)
end
end
end
end
end
end

0 comments on commit 25e6ac7

Please sign in to comment.