From: Ian MacLeod Date: 2011-07-01T06:15:26+09:00 Subject: [ruby-core:37699] [Ruby 1.9 - Bug #4952][Open] Integer#chr(Encoding::*) behaves inconsistently with negative or large values Issue #4952 has been reported by Ian MacLeod. ---------------------------------------- Bug #4952: Integer#chr(Encoding::*) behaves inconsistently with negative or large values http://redmine.ruby-lang.org/issues/4952 Author: Ian MacLeod Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.4] These seem like they should all be raising RangeError; and appear to indicate that values are overflowing/being cast improperly: ruby-1.9.2-p180 :001 > -1.chr(Encoding::UTF_8) => "\xFF" ruby-1.9.2-p180 :002 > -2.chr(Encoding::UTF_8) => "\xFE" ruby-1.9.2-p180 :006 > -1.chr(Encoding::UTF_16LE) => "\uD7BF\xFF\xDF" ruby-1.9.2-p180 :007 > -2.chr(Encoding::UTF_16LE) => "\uD7BF\xFE\xDF" ruby-1.9.2-p180 :008 > -1234.chr(Encoding::UTF_16LE) => "\uD7BE\x2E\xDF" ruby-1.9.2-p180 :009 > -1.chr(Encoding::EUC_JP) ArgumentError: invalid codepoint 0xffffffff in EUC-JP Examples that are inconsistent: ruby-1.9.2-p180 :005 > -1.chr(Encoding::WINDOWS_1251) RangeError: 4294967295 out of char range Examples that seem to be fine: ruby-1.9.2-p180 :003 > -3.chr(Encoding::UTF_8) RangeError: -3 out of char range -- http://redmine.ruby-lang.org