From: meta@... Date: 2014-08-14T18:21:14+00:00 Subject: [ruby-core:64359] [ruby-trunk - Bug #10132] [Open] unpack() ignores default encoding when generating strings, always uses ASCII-8BIT Issue #10132 has been reported by mathew murphy. ---------------------------------------- Bug #10132: unpack() ignores default encoding when generating strings, always uses ASCII-8BIT https://bugs.ruby-lang.org/issues/10132 * Author: mathew murphy * Status: Open * Priority: Normal * Assignee: * Category: * Target version: * ruby -v: ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN ---------------------------------------- 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" -- https://bugs.ruby-lang.org/