Project

General

Profile

Actions

Bug #20566

closed

string << 0xC2 should raise a RangeError if the string encoding is Encoding::ASCII

Added by postmodern (Hal Brodigan) 6 months ago. Updated 6 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.0preview1 (2024-05-16 master 9d69619623) [x86_64-linux]
[ruby-core:118257]

Description

I noticed that appending extended ASCII characters (0x80 - 0xff) works when the String's encoding is Encoding::ASCII, as well as Encoding::ASCII_8BIT. I was under the impression that Encoding::ASCII only covers the regular ASCII character set (0x00 - 0x7F). I believe appending 0xC2 to a String with Encoding::ASCII should raise a RangeError.

Steps To Reproduce

str = String.new(encoding: Encoding::ASCII)
str << 0xC2

Expected Result

RangeError: character 194 is out of range

Actual Result

"\xC2"

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #18973: Kernel#sprintf: %c allows codepoints above 127 for 7-bits ASCII encodingClosedActions
Actions #1

Updated by nobu (Nobuyoshi Nakada) 6 months ago

  • Related to Bug #18973: Kernel#sprintf: %c allows codepoints above 127 for 7-bits ASCII encoding added
Actions #3

Updated by nobu (Nobuyoshi Nakada) 6 months ago

  • Status changed from Open to Closed

Applied in changeset git|dd8903fed72c2d06fe7a0ca6b5ef88e9140be451.


[Bug #20566] Mention out-of-range argument cases in String#<<

Also [Bug #18973].

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0