summaryrefslogtreecommitdiff
path: root/pack.c
diff options
context:
space:
mode:
Diffstat (limited to 'pack.c')
-rw-r--r--pack.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/pack.c b/pack.c
index df25231610..2ecb2d68d6 100644
--- a/pack.c
+++ b/pack.c
@@ -519,8 +519,15 @@ pack_pack(VALUE ary, VALUE fmt)
ptr = RSTRING_PTR(from);
plen = RSTRING_LEN(from);
OBJ_INFECT(res, from);
- enc = rb_enc_compatible(res, from);
- rb_enc_associate(res, enc);
+ switch (type) {
+ case 'a': case 'A': case 'Z':
+ enc = rb_enc_compatible(res, from);
+ rb_enc_associate(res, enc);
+ break;
+ default:
+ rb_enc_associate(res, rb_ascii8bit_encoding());
+ break;
+ }
}
if (p[-1] == '*')