summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--lib/rexml/parsers/xpathparser.rb3
-rw-r--r--test/rexml/test_elements.rb9
3 files changed, 20 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 1407d0e3bd1..9f822714f36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Jun 11 16:04:03 2011 Kouhei Sutou <kou@cozmixng.org>
+
+ * lib/rexml/parsers/xpathparser.rb
+ (REXML::Parsers::XPathParser#parse),
+ test/rexml/test_elements.rb
+ (ElementsTester::test_each_with_frozen_condition):
+ don't modify original XPath. fixes #4164
+ Reported by Pavel Shved. Thanks!!!
+
Sat Jun 11 15:53:27 2011 Kouhei Sutou <kou@cozmixng.org>
* test/rexml/test_elements.rb (ElementsTester): remove needless
diff --git a/lib/rexml/parsers/xpathparser.rb b/lib/rexml/parsers/xpathparser.rb
index 780e3126712..e643d115110 100644
--- a/lib/rexml/parsers/xpathparser.rb
+++ b/lib/rexml/parsers/xpathparser.rb
@@ -17,8 +17,9 @@ module REXML
end
def parse path
+ path = path.dup
path.gsub!(/([\(\[])\s+/, '\1') # Strip ignorable spaces
- path.gsub!( /\s+([\]\)])/, '\1' )
+ path.gsub!( /\s+([\]\)])/, '\1')
parsed = []
path = OrExpr(path, parsed)
parsed
diff --git a/test/rexml/test_elements.rb b/test/rexml/test_elements.rb
index b7c7c267ed4..e5e209ecdc3 100644
--- a/test/rexml/test_elements.rb
+++ b/test/rexml/test_elements.rb
@@ -84,6 +84,15 @@ class ElementsTester < Test::Unit::TestCase
assert_equal 7, count
end
+ def test_each_with_frozen_condition
+ doc = Document.new('<books><book name="Ruby"/><book name="XML"/></books>')
+ names = []
+ doc.root.elements.each('book'.freeze) do |element|
+ names << element.attributes["name"]
+ end
+ assert_equal(["Ruby", "XML"], names)
+ end
+
def test_to_a
doc = Document.new '<a>sean<b/>elliott<c/></a>'
assert_equal 2, doc.root.elements.to_a.size