#346 new
Andreas Krüger

assert_have_xpath starting with /// results in Nokogiri::XML::SyntaxError when checking XML nodeset

Reported by Andreas Krüger | January 22nd, 2010 @ 05:35 AM


assert_have_xpath is given a stringlike which happens to be Nokogiri::XML::NodeSet.

This gets bitten by some special logic which destroys XPath statements that happen to start with “///”. (This is an XPath idiom for “anywhere in the document”.)

The result is an (undeserved)

Nokogiri::XML::XPath::SyntaxError ... Invalid expression.

I attach a couple of tests as a patch. The first test works fine, the second exposes this bug.

The problem is caused by the following code stance in

      def nokogiri_matches(stringlike)
        if Nokogiri::XML::NodeSet === stringlike
          @query = query.gsub(%r'^//', './/')
          @query = query

This gsub comes with no comment. So it remains somewhat unclear (at least to me) why this is done that way. In my humble opinion, messing with XPath provided by the user can hardly fail to constitute a bug.

For a workaround,add a space. “ ///” works as expected.

With best regards, and thank you for providing fine software,


Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

People watching this ticket