From 4d86bbcf206e70cc8005f0abee58207a6ae46e67 Mon Sep 17 00:00:00 2001 From: Piotr Szmielew Date: Tue, 22 May 2012 01:57:14 +0200 Subject: [PATCH] fixing bug in java nokogiri, that cause xpath xmlns:Tag to return always empty array. test provided - with this testcase --- lib/nokogiri/xml/node.rb | 1 + test/xml/test_xpath.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/nokogiri/xml/node.rb b/lib/nokogiri/xml/node.rb index 65054758fc8..35818decbc3 100644 --- a/lib/nokogiri/xml/node.rb +++ b/lib/nokogiri/xml/node.rb @@ -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 diff --git a/test/xml/test_xpath.rb b/test/xml/test_xpath.rb index d4392d6a768..15a1f85c4ba 100644 --- a/test/xml/test_xpath.rb +++ b/test/xml/test_xpath.rb @@ -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{ + + + a + + } + + 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