Issue #12128 has been updated by Robert A. Heiler.


I believe that this is actually how ruby may have behaved before the transition into frozen strings
already; at the least, I seem to distinctly remember that, if I write a method such as:

---

require 'pp'

def foo(i = ARGV)
  pp i
end

foo

---

Then the input was considered "tainted", which I assume may refer to external input in
general, and the Strings that are in ARGV were always frozen.

So I think one always had to write code that would handle this situation properly. This
does not say anything about your proposal by the way, I have no particular pro or contra
opinion whatsoever, but I think that this was how ruby always treated ARGV. (I would usually
pass this through a setter method that will do the proper sanitizing for me; that is, how
I would respond to user input in general. It may be interesting to know how OptionParser
/ optparse handles commandline input, I personally tend to be very lazy and am often fine
for small classes to just check against an internal menu() method, which would select
the behaviour for the given class, such as --disable-colours and such to control colour
output, and so on and so forth.)

----------------------------------------
Bug #12128: Strings in `ARGV` are frozen
https://bugs.ruby-lang.org/issues/12128#change-57215

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
It is not clear how the frozen status of strings in `ARGV` are to be described, but regardless of what I try to do (i.e. set frozen string pragma as false, which is probably irrelevant because the strings are already created at the time of file load), the strings appear frozen. I ran the following file `foo.rb` as `ruby foo.rb bar`:

~~~RUBY
#!/usr/bin/env ruby
# frozen_string_literal: false
ARGV.first.frozen? #=> true
ARGV.first.upcase! #=> can't modify frozen String (RuntimeError)
~~~

I believe this is a bug. If not, I would like to know what determines the frozen status of the strings in `ARGV`. Is it a feature that they are always frozen?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>