Bug #4161
closedReXML wants "elements.each" argument to be not frozen
Description
=begin
Here's a simple program that uses ReXML:
require 'rexml/document'
doc = REXML::Document.new File.new(ARGV[0])
query = "element".freeze
doc.elements.each(query) do |elem|
puts elem.name
end
I expected the program to work without errors (when called with a valid XML file as its first command-line argument). However the program fails with a backtrace:
/home/pavel/ruby-1.9/lib/ruby/1.9.1/rexml/parsers/xpathparser.rb:20:in gsub!': can't modify frozen string (RuntimeError) from /home/pavel/ruby-1.9/lib/ruby/1.9.1/rexml/parsers/xpathparser.rb:20:in
parse'
from /home/pavel/ruby-1.9/lib/ruby/1.9.1/rexml/xpath_parser.rb:57:in parse' from /home/pavel/ruby-1.9/lib/ruby/1.9.1/rexml/xpath.rb:64:in
each'
from /home/pavel/ruby-1.9/lib/ruby/1.9.1/rexml/element.rb:906:in each' from a.rb:5:in
'
If the string is not frozen, it works well. In ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux] it also works well.
Is there any reason to require the argument of elements_each to be frozen?
=end