Project

General

Profile

Actions

Bug #20389

closed

Issue with chilled strings and mutability after 12be40ae

Added by mdalessio (Mike Dalessio) 3 months ago. Updated 3 months ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 3.4.0dev (2024-03-23T16:40:17Z master 8265a7531f) [x86_64-linux]
[ruby-core:117302]

Description

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:

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.

Updated by byroot (Jean Boussier) 3 months ago

  • Assignee set to byroot (Jean Boussier)
  • Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.0: DONTNEED, 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED
Actions #3

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Closed

Applied in changeset git|fdd7ffb70ca6e9f7d790aadde86dbc8172e19f4d.


[Bug #20389] Chilled string cannot be a shared root

Updated by byroot (Jean Boussier) 3 months ago

Thank you @nobu (Nobuyoshi Nakada), I was about to look into it :)

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0