Actions
Bug #10132
closedunpack() ignores default encoding when generating strings, always uses ASCII-8BIT
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
Backport:
Description
New strings are generated in the default encoding:
irb> __ENCODING__.name
=> "UTF-8"
irb> "ünicode".encoding.name
=> "UTF-8"
...but not if they're generated by unpack:
irb> "ünicode".split.pack('M*').unpack('M*').first
=> "\xC3\xBCnicode"
irb> "ünicode".split.pack('M*').unpack('M*').first.encoding.name
=> "ASCII-8BIT"
Workaround is to force the encoding on every string unpack generates:
irb> "ünicode".split.pack('M*').unpack('M*').first.force_encoding(__ENCODING__.name)
=> "ünicode"
Actions
Like0
Like0Like0Like0Like0