diff --git a/ChangeLog b/ChangeLog index 1e14820b65..8ccac2731f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Jun 27 03:16:56 2009 Yukihiro Matsumoto + + * numeric.c (int_chr): use default_internal encoding as default + destination encoding if set. [ruby-dev:38717] + Sat Jun 27 03:09:04 2009 Yukihiro Matsumoto * io.c (argf_rewind): need to rewind $. and ARGF.lineno. diff --git a/numeric.c b/numeric.c index 8435d7f691..f3aa757874 100644 --- a/numeric.c +++ b/numeric.c @@ -1945,10 +1945,15 @@ int_chr(int argc, VALUE *argv, VALUE num) switch (argc) { case 0: - if (i < 0 || 0xff < i) { + if (i < 0) { out_of_range: rb_raise(rb_eRangeError, "%"PRIdVALUE " out of char range", i); } + if (0xff < i) { + enc = rb_default_internal_encoding(); + if (!enc) goto out_of_range; + goto decode; + } c = (char)i; if (i < 0x80) { return rb_usascii_str_new(&c, 1); @@ -1964,6 +1969,7 @@ int_chr(int argc, VALUE *argv, VALUE num) } enc = rb_to_encoding(argv[0]); if (!enc) enc = rb_ascii8bit_encoding(); + decode: #if SIZEOF_INT < SIZEOF_LONG if (i > INT_MAX) goto out_of_range; #endif