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

xpath searching in fragments is inconsistent #1438

Closed
tnt opened this issue Mar 1, 2016 · 2 comments
Closed

xpath searching in fragments is inconsistent #1438

tnt opened this issue Mar 1, 2016 · 2 comments

Comments

@tnt
Copy link

tnt commented Mar 1, 2016

In the following session I'd expect three text nodes"

[1] pry(main)> require 'nokogiri'
=> true
[2] pry(main)> Nokogiri::VERSION
=> "1.6.7.2"
[3] pry(main)> doc = Nokogiri::HTML.fragment 'some text <p>more text</p> excess text'
=> #(DocumentFragment:0x2acb9d91fc60 {
  name = "#document-fragment",
  children = [
    #(Text "some text "),
    #(Element:0x2acb9d91f7b0 { name = "p", children = [ #(Text "more text")] }),
    #(Text " excess text")]
  })
[4] pry(main)> doc.xpath('//text()')
=> []
[5] pry(main)> doc.xpath('text()')
=> [#<Nokogiri::XML::Text:0x2acb9d91f8a0 "some text ">, #<Nokogiri::XML::Text:0x2acb9d91f65c " excess text">]
[6] pry(main)> RUBY_VERSION
=> "2.1.5"
[7] pry(main)> RUBY_PLATFORM
=> "x86_64-linux"

I didn't do any special. Just gem install.

@flavorjones
Copy link
Member

There are some known edge cases around xpath-searching fragments; the workaround is to search with ".//" as the prefix:

2.3.1 :007 > doc.xpath ".//text()"
 => [#<Nokogiri::XML::Text:0x86e1d8 "some text ">, #<Nokogiri::XML::Text:0xadd950 "more text">, #<Nokogiri::XML::Text:0xaddf7c " excess text">] 

We should really fix this. Leaving open.

@flavorjones flavorjones changed the title xpath('//text()') doesn't work xpath searching in fragments is inconsistent Oct 3, 2016
@flavorjones
Copy link
Member

This is the same issue described in #572, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants