summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--lib/rexml/xpath_parser.rb3
-rw-r--r--test/rexml/test_xpath.rb23
3 files changed, 31 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 725ce97ca4..441065a644 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Sep 17 23:44:07 2010 Kouhei Sutou <kou@cozmixng.org>
+
+ * 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@cozmixng.org>
* test/rexml/test_sax.rb: don't use thread and sleep to avoid slow test.
diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb
index 11950ecd93..d9088a25d9 100644
--- a/lib/rexml/xpath_parser.rb
+++ b/lib/rexml/xpath_parser.rb
@@ -434,7 +434,8 @@ module REXML
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 )
diff --git a/test/rexml/test_xpath.rb b/test/rexml/test_xpath.rb
index f3a27cf154..d7ab9620a8 100644
--- a/test/rexml/test_xpath.rb
+++ b/test/rexml/test_xpath.rb
@@ -1053,4 +1053,27 @@ EOF
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