Ticket #32 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

preceding-sibling fails attempting delete_if on nil nodeset

Reported by: daz Owned by: ser
Priority: normal Milestone: 3.1.4
Component: XPath Version: 3.1.3
Severity: major Keywords:
Cc: Ruby version: 1.9.x
Operating system: All

Description

Reported by Dan Kohn on ruby-talk/c.l.ruby

An XPath search which worked for ["3.1.2.1", "1.8.2", "2004-12-25"] fails using 3.1.3 under Ruby 1.9.0 ["3.1.3", "1.9.0", "2005-07-16"] (-or- 1.8.2)

Unit test included below.

From tinkering, I noticed that XPathParser#expr (when :preceding-sibling) starts with a nodeset of [] - so the for loop is skipped - preceding_siblings is "UNDEFINED" (nil) and gets assigned to nodeset.

Just for a giggle, I tried nodeset = preceding_siblings || [] but that sent me into a closed loop; which is where my short debugging effort expired ;-)

require 'test/unit'
require 'rexml/document'

p [REXML::Version, RUBY_VERSION, RUBY_RELEASE_DATE]

# daz - for report by Dan Kohn in:
#  http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/156328
class XPathTesterDd < Test::Unit::TestCase
  include REXML

  def setup
    @@docDd = Document.new(<<-EOS, :ignore_whitespace_nodes => :all)
      <a>
        <b x='ab01A'>
          <c y='abc01A'>Success</c>
        </b>
        <b x='ab02A' y='ab02B'>
          <c>abc02C</c>
        </b>
      </a>
    EOS
  end

  def test_Dd_preceding_sibling_children
    arr = []
    XPath.each(@@docDd, "//b[@x='ab02A']/preceding-sibling::b/child::*") do |cell|
      arr << cell.texts.to_s
    end
    assert_equal( 'Success', arr.join )
  end

  def test_Dd_preceding_sibling_all
    arr = []
    XPath.each(@@docDd, "//b[@x='ab02A']/preceding-sibling::*") do |cell|
      arr << cell.to_s
    end
    assert_equal( "<b x='ab01A'><c y='abc01A'>Success</c></b>", arr.join )
  end
end

Hope that's OK, Sean. No point in me leaving contact info, 'cos I know nothing :-)

Thanks,

daz

Change History

Changed 3 years ago by ser

  • status changed from new to assigned

Changed 3 years ago by ser

Confirmed. The bug is independent of the Ruby version.

Changed 3 years ago by ser

  • status changed from assigned to closed
  • resolution set to fixed

Fixed by changeset:1142

Note: See TracTickets for help on using tickets.