Project

General

Profile

Actions

Bug #1836

closed

Can change encoding on frozen String

Added by candlerb (Brian Candler) over 14 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-07-18 trunk 24186) [i686-linux]
Backport:
[ruby-core:24609]

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

Actions #1

Updated by duerst (Martin Dürst) over 14 years ago

  • Assignee set to duerst (Martin Dürst)

=begin
working on a fix
=end

Actions #2

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

Actions #3

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

Actions #4

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

Actions #5

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0