From f2c6f71531e9463e3a05b9d96b64f480ec92bb38 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 2 Jun 2021 14:57:11 -0400 Subject: [PATCH] test: add coverage for xpath recursion depth fix Related to #2257 --- test/xml/test_xpath.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/xml/test_xpath.rb b/test/xml/test_xpath.rb index fe22646ba1..504a30caa8 100644 --- a/test/xml/test_xpath.rb +++ b/test/xml/test_xpath.rb @@ -470,6 +470,27 @@ def test_xpath_syntax_error end end + def test_huge_xpath_query + if Nokogiri.uses_libxml?("~>2.9.11") && !Nokogiri::VERSION_INFO["libxml"]["patches"]&.include?("0007-Fix-XPath-recursion-limit.patch") + skip("libxml2 under test is broken with respect to xpath query recusion depth") + end + + # real world example + # from https://github.com/sparklemotion/nokogiri/issues/2257 + query = File.read(File.join(ASSETS_DIR, 'huge-xpath-query.txt')) + + doc = Nokogiri::XML::Document.parse("") + handler = Class.new do + def seconds(context) + 42 + end + def add(context, rhs) + 42 + end + end + doc.xpath(query, {"ct" => "https://test.nokogiri.org/ct", "date" => "https://test.nokogiri.org/date"}, handler.new) + end + describe "nokogiri-builtin:css-class xpath function" do before do @doc = Nokogiri::HTML::Document.parse("")