Bug #1836
closedCan change encoding on frozen String
Description
=begin
String#encode! lets you change the encoding on a frozen String, as long as the character sequence is unchanged by the operation.
s = "hello"
=> "hello"
s.freeze
=> "hello"
s.encode!("ISO-8859-1")
=> "hello"
s.encoding
=> #Encoding:ISO-8859-1
=end
Updated by duerst (Martin Dürst) over 14 years ago
- Assignee set to duerst (Martin Dürst)
=begin
working on a fix
=end
Updated by duerst (Martin Dürst) over 14 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
Applied in changeset r24322.
=end
Updated by duerst (Martin Dürst) over 14 years ago
=begin
The current version raises an error even if encode! is a dummy operation, e.g. for
'abcd'.force_encoding(encoding_foo).freeze.encode!(encoding_foo)
Please comment on whether I can close this bug or not.
=end
Updated by candlerb (Brian Candler) over 14 years ago
=begin
Well, force_encoding raises an exception even if you specify the same one it already has:
s = "abcd"
=> "abcd"
s.freeze.force_encoding(s.encoding)
RuntimeError: can't modify frozen string
So your new behaviour would be consistent with that. Whether that's the desired behaviour is not really for me to decide.
I guess it would be consistent with other null modify operations, such as
s.strip!
RuntimeError: can't modify frozen string
s.tr!("f","f")
RuntimeError: can't modify frozen string
=end
Updated by runpaint (Run Paint Run Run) over 14 years ago
=begin
So your new behaviour would be consistent with that. Whether that's the desired behaviour is not really
for me to decide.
It was decided in http://redmine.ruby-lang.org/issues/show/1550 that no-ops on frozen objects should raise RuntimeErrors. :-)
=end