Project

General

Profile

Bug #1836

Can change encoding on frozen String

Added by candlerb (Brian Candler) over 10 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
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

Associated revisions

Revision 5e85648b
Added by duerst (Martin Dürst) over 10 years ago

  • transcode.c: added check for frozen string for encode! (see Bug #1836)

  • test/ruby/test_transcode.rb: added tests for the above

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 24322
Added by duerst (Martin Dürst) over 10 years ago

  • transcode.c: added check for frozen string for encode! (see Bug #1836)

  • test/ruby/test_transcode.rb: added tests for the above

Revision 24322
Added by duerst (Martin Dürst) over 10 years ago

  • transcode.c: added check for frozen string for encode! (see Bug #1836)

  • test/ruby/test_transcode.rb: added tests for the above

Revision 24322
Added by duerst (Martin Dürst) over 10 years ago

  • transcode.c: added check for frozen string for encode! (see Bug #1836)

  • test/ruby/test_transcode.rb: added tests for the above

Revision 24322
Added by duerst (Martin Dürst) over 10 years ago

  • transcode.c: added check for frozen string for encode! (see Bug #1836)

  • test/ruby/test_transcode.rb: added tests for the above

Revision 24322
Added by duerst (Martin Dürst) over 10 years ago

  • transcode.c: added check for frozen string for encode! (see Bug #1836)

  • test/ruby/test_transcode.rb: added tests for the above

Revision 24322
Added by duerst (Martin Dürst) over 10 years ago

  • transcode.c: added check for frozen string for encode! (see Bug #1836)

  • test/ruby/test_transcode.rb: added tests for the above

History

#1

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

  • Assignee set to duerst (Martin Dürst)

=begin
working on a fix
=end

#2

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

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r24322.
=end

#3

Updated by duerst (Martin Dürst) over 10 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

#4

Updated by candlerb (Brian Candler) over 10 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

#5

Updated by runpaint (Run Paint Run Run) over 10 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

Also available in: Atom PDF