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

Bugfix in Jruby that cause xpath with 'xmlns:' to return empty results #681

Closed
wants to merge 2 commits into from
Closed
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 lib/nokogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def xpath *paths
ctx = XPathContext.new(self)
ctx.register_namespaces(ns)
path = path.gsub(/\/xmlns:/,'/:') unless Nokogiri.uses_libxml?
path = path.gsub(/xmlns:/, ' :') unless Nokogiri.uses_libxml?

binds.each do |key,value|
ctx.register_variable key.to_s, value
Expand Down
13 changes: 13 additions & 0 deletions test/xml/test_xpath.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,19 @@ def bool_function(value)
}.new)
assert_equal foo, doc.xpath("//foo")
end

def test_very_specific_xml_xpath_making_problems_in_jruby
xml_string = %q{<?xml version="1.0" encoding="UTF-8"?>
<ONIXMessage xmlns:elibri="http://elibri.com.pl/ns/extensions" release="3.0" xmlns="http://www.editeur.org/onix/3.0/reference">
<Product>
<RecordReference>a</RecordReference>
</Product>
</ONIXMessage>}

xml_doc = Nokogiri::XML(xml_string)
onix = xml_doc.children.first
assert_equal 'a', onix.at_xpath('xmlns:Product').at_xpath('xmlns:RecordReference').text
end
end
end
end