Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spinoso_string::String::chars does not yield encoded strings #2669

Open
lopopolo opened this issue Dec 26, 2023 · 0 comments
Open

spinoso_string::String::chars does not yield encoded strings #2669

lopopolo opened this issue Dec 26, 2023 · 0 comments
Labels
A-ruby-core Area: Ruby Core types. A-spec Area: ruby/spec infrastructure and completeness. C-bug Category: This is a bug.

Comments

@lopopolo
Copy link
Member

lopopolo commented Dec 26, 2023

The 1-character strings yielded by String#chars and String#each_char should share the encoding of the source string.

MRI 3.3.0

$ irb
[3.3.0] > "abc".chars.map { _1.encoding }
=> [#<Encoding:UTF-8>, #<Encoding:UTF-8>, #<Encoding:UTF-8>]
[3.3.0] > "abc".b.chars.map { _1.encoding }
=> [#<Encoding:ASCII-8BIT>, #<Encoding:ASCII-8BIT>, #<Encoding:ASCII-8BIT>]
[3.3.0] > "你好".chars.length
=> 2
[3.3.0] > "你好".b.chars.length
=> 6
[3.3.0] > "你好".chars.map { _1.valid_encoding? }
=> [true, true]
[3.3.0] > "你好".b.chars.map { _1.valid_encoding? }
=> [true, true, true, true, true, true]

Artichoke

$ docker run -it docker.io/artichokeruby/artichoke:slim-bookworm-nightly airb
artichoke 0.1.0-pre.0 (2023-12-26 revision 7076) [x86_64-unknown-linux-gnu]
[rustc 1.72.0 (5680fa18f 2023-08-23) on x86_64-unknown-linux-gnu]
>>> "abc".chars.map { _1.encoding }
=> [#<Encoding:UTF-8>, #<Encoding:UTF-8>, #<Encoding:UTF-8>]
>>> "abc".b.chars.map { _1.encoding }
=> [#<Encoding:UTF-8>, #<Encoding:UTF-8>, #<Encoding:UTF-8>]
>>> "你好".chars.length
=> 2
>>> "你好".b.chars.length
=> 6
>>> "你好".chars.map { _1.valid_encoding? }
=> [true, true]
>>> "你好".b.chars.map { _1.valid_encoding? }
=> [false, false, false, false, false, false]
@lopopolo lopopolo added C-bug Category: This is a bug. A-ruby-core Area: Ruby Core types. A-spec Area: ruby/spec infrastructure and completeness. labels Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ruby-core Area: Ruby Core types. A-spec Area: ruby/spec infrastructure and completeness. C-bug Category: This is a bug.
Development

No branches or pull requests

1 participant