Project

General

Profile

Actions

Bug #5864

closed

Integer#chr raises on some invalid codepoints but returns an invalidly-encoded string for others

Added by john_firebaugh (John Firebaugh) almost 13 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
Backport:
[ruby-core:41973]

Description

=begin
Integer#chr raises RangeError on some invalid codepoints, but on others it returns an invalidly-encoded string.

0x0100.chr("EUC-JP") # Raises
0xA1A0.chr("EUC-JP").valid_encoding? #=> false
0x80.chr("SHIFT_JIS").valid_encoding? #=> false

0xA1.chr("EUC-JP") # Raises
0xE0.chr("SHIFT_JIS").valid_encoding? #=> false

If this is not a bug, could someone please explain the semantics for when Integer#chr should raise RangeError versus when it should return an invalidly-encoded string?
=end


Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #5855: inconsistent treatment of 8 bit characters in US-ASCIIClosednaruse (Yui NARUSE)01/07/2012Actions
Is duplicate of Ruby master - Bug #5863: Integer#chr may return a string with multiple charactersClosed01/08/2012Actions
Actions #1

Updated by naruse (Yui NARUSE) almost 13 years ago

  • Status changed from Open to Closed

This issue was solved with changeset r34236.
John, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • numeric.c (rb_enc_uint_char): raise RangeError when added codepoint
    is invalid. [Feature #5855] [Bug #5863] [Bug #5864]

  • string.c (rb_str_concat): ditto.

  • string.c (rb_str_concat): set encoding as ASCII-8BIT when the string
    is US-ASCII and the argument is an integer greater than 127.

  • regenc.c (onigenc_mb2_code_to_mbclen): rearrange error code.

  • enc/euc_jp.c (code_to_mbclen): ditto.

  • enc/shift_jis.c (code_to_mbclen): ditto.

Actions

Also available in: Atom PDF

Like0
Like0