[ruby-core:93248] [Ruby trunk Bug#15926] Edge case issue with String#uminus
From:
luke.gru@...
Date:
2019-06-19 13:33:38 UTC
List:
ruby-core #93248
Issue #15926 has been updated by luke-gru (Luke Gruber).
Hi Jeremy, thanks for the patch. I agree with the strategy of just dealing with this in `str_uminus` directly instead of fiddling around in the tricky `rb_fstring` function. However there's still an issue when the string is a regular String, but tainted or has ivars. In this case, it still gets frozen.
----------------------------------------
Bug #15926: Edge case issue with String#uminus
https://bugs.ruby-lang.org/issues/15926#change-78699
* Author: luke-gru (Luke Gruber)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v:
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
I was working on issue related to code in `rb_fstring`(https://github.com/ruby/ruby/pull/2233) and saw some weird behavior in the function,
freezing the given string if it's not a "bare" string and it's small enough to be embedded.
The issue comes up in the following edge case:
class MyString < String
end
non_frozen = MyString.new("nonfrozen")
frozen = -non_frozen # deduplicates, but shouldn't freeze receiver
non_frozen << " added" # raises FrozenError
I'm not sure what the correct behavior should be with a subclass and String#uminus. Should it return
a frozen regular String or a frozen copy of the given class's string?
Not a practical concern (not often come upon I'm sure), but I think a valid one.
---Files--------------------------------
str-uminus-freeze-fix.patch (1.38 KB)
--
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>