[前][次][番号順一覧][スレッド一覧]

ruby-changes:17285

From: kou <ko1@a...>
Date: Fri, 17 Sep 2010 23:47:26 +0900 (JST)
Subject: [ruby-changes:17285] Ruby:r29288 (trunk): * lib/rexml/xpath_parser.rb, test/rexml/test_xpath.rb:

kou	2010-09-17 23:47:20 +0900 (Fri, 17 Sep 2010)

  New Revision: 29288

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29288

  Log:
    * lib/rexml/xpath_parser.rb, test/rexml/test_xpath.rb:
      add missing method availability check. [ruby-core:32447]
      Reported by Wiebe Cazemier. Thanks!!!

  Modified files:
    trunk/ChangeLog
    trunk/lib/rexml/xpath_parser.rb
    trunk/test/rexml/test_xpath.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29287)
+++ ChangeLog	(revision 29288)
@@ -1,3 +1,9 @@
+Fri Sep 17 23:44:07 2010  Kouhei Sutou  <kou@c...>
+
+	* lib/rexml/xpath_parser.rb, test/rexml/test_xpath.rb:
+	add missing method availability check. [ruby-core:32447]
+	Reported by Wiebe Cazemier. Thanks!!!
+
 Fri Sep 17 23:23:26 2010  Kouhei Sutou  <kou@c...>
 
 	* test/rexml/test_sax.rb: don't use thread and sleep to avoid slow test.
Index: lib/rexml/xpath_parser.rb
===================================================================
--- lib/rexml/xpath_parser.rb	(revision 29287)
+++ lib/rexml/xpath_parser.rb	(revision 29288)
@@ -434,7 +434,8 @@
         when :and
           left = expr( path_stack.shift, nodeset.dup, context )
           #puts "LEFT => #{left.inspect} (#{left.class.name})"
-          if left == false || left.nil? || !left.inject(false) {|a,b| a | b}
+          return [] unless left
+          if left.respond_to?(:inject) and !left.inject(false) {|a,b| a | b}
             return []
           end
           right = expr( path_stack.shift, nodeset.dup, context )
Index: test/rexml/test_xpath.rb
===================================================================
--- test/rexml/test_xpath.rb	(revision 29287)
+++ test/rexml/test_xpath.rb	(revision 29288)
@@ -1053,4 +1053,27 @@
     r = REXML::XPath.match( d, %q{/a/b[c='3']} )
     assert_equal(1, r.size())
   end
+
+  def test_or_and
+    doc = "
+<html>
+  <head>
+    <title>test</title>
+  </head>
+  <body>
+    <p>
+      A <a rel=\"sub\" href=\"/\">link</a>.
+    </p>
+  </body>
+</html>
+"
+
+    xmldoc = REXML::Document.new(doc)
+    xpath = "descendant::node()[(local-name()='link' or local-name()='a') and @rel='sub']"
+    hrefs = []
+    xmldoc.elements.each(xpath) do |element|
+      hrefs << element.attributes["href"]
+    end
+    assert_equal(["/"], hrefs, "Bug #3842 [ruby-core:32447]")
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]