Bug #20389
Updated by mdalessio (Mike Dalessio) 10 months ago
Commit 12be40ae introduced the concept of "chilled" strings when code is compiled with frozen-string-literals not explicitly enabled or disabled. I believe I've found a related bug, which I've bisected to this commit.
This reproduction has been simplified from a failing test case in the `http-cookie` gem:
``` ruby
puts RUBY_DESCRIPTION
re = %r{.(?<thing>.*)}
input = "x/dir[]/file.html"
match = re.match(input) # => "#<MatchData \"x/dir[]/file.html\" thing:\"/dir[]/file.html\">"
thing = match[:thing]
puts "before: #{thing.inspect}"
input[match.begin(:thing)...match.end(:thing)] = "/dir%5B%5D/file.html"
puts "after : #{thing.inspect}"
exit 1 unless thing == "/dir[]/file.html"
```
Ruby 3.3.0 and earlier is fine:
```
$ ruby ./issue-chilled-strings.rb
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux]
before: "/dir[]/file.html"
after : "/dir[]/file.html"
```
Master with frozen string explicitly disabled passes:
```
$ ruby --disable-frozen-string-literal ./issue-chilled-strings.rb
ruby 3.4.0dev (2024-03-23T16:40:17Z master 8265a7531f) [x86_64-linux]
before: "/dir[]/file.html"
after : "/dir[]/file.html"
```
Master with frozen strings explicitly enabled fails as expected:
```
$ ruby --enable-frozen-string-literal ./issue-chilled-strings.rb
ruby 3.4.0dev (2024-03-23T16:40:17Z master 8265a7531f) [x86_64-linux]
before: "/dir[]/file.html"
./issue-chilled-strings.rb:12:in 'String#[]=': can't modify frozen String: "x/dir[]/file.html" (FrozenError)
from ./issue-chilled-strings.rb:12:in '<main>'
```
But master with no frozen string setting ("chilled") fails, and modifies what should be a frozen string:
```
$ ruby ./issue-chilled-strings.rb
ruby 3.4.0dev (2024-03-23T16:40:17Z master 8265a7531f) [x86_64-linux]
before: "/dir[]/file.html"
after : "/dir%5B%5D/file."
```
I believe in this case, the chilled warning should be emitted, but then the frozen string should not be modified.