Actions
Bug #20566
closedstring << 0xC2 should raise a RangeError if the string encoding is Encoding::ASCII
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.0preview1 (2024-05-16 master 9d69619623) [x86_64-linux]
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"
Updated by nobu (Nobuyoshi Nakada) 7 months ago
- Related to Bug #18973: Kernel#sprintf: %c allows codepoints above 127 for 7-bits ASCII encoding added
Updated by nobu (Nobuyoshi Nakada) 7 months ago
It is a spec.
Updated by nobu (Nobuyoshi Nakada) 7 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
Like0
Like0Like0Like0