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

String#split wrong behavior and return value #2304

Closed
dustalov opened this issue Apr 21, 2013 · 4 comments
Closed

String#split wrong behavior and return value #2304

dustalov opened this issue Apr 21, 2013 · 4 comments

Comments

@dustalov
Copy link

It seems that String#split method corrupts the encodings of generated strings and returns TrueClass instead of Array.

>> RUBY_DESCRIPTION
=> "rubinius 2.0.0.rc1 (1.9.3 dec3ff31 yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]"
>> s = 'а б в'
=> "а б в"
>> s.encoding
=> #<Encoding:UTF-8>
>> a, b, c = s.split
=> true
>> a
=> "\xD0\xB0"
>> a.encoding
=> #<Encoding:ASCII-8BIT>
>> b
=> "\xD0\xB1"
>> b.encoding
=> #<Encoding:ASCII-8BIT>
>> c
=> "\xD0\xB2"
>> c.encoding
=> #<Encoding:ASCII-8BIT>
@dustalov
Copy link
Author

>> RUBY_DESCRIPTION
=> "ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]"
>> s = 'а б в'
=> "а б в"
>> s.encoding
=> #<Encoding:UTF-8>
>> a, b, c = s.split
=> ["а", "б", "в"]
>> a
=> "а"
>> a.encoding
=> #<Encoding:UTF-8>
>> b
=> "б"
>> b.encoding
=> #<Encoding:UTF-8>
>> c
=> "в"
>> c.encoding
=> #<Encoding:UTF-8>

@leocassarani
Copy link
Member

There are two unrelated issues here:

  • Destructuring assignments return true instead of the thing being destructured. This is not a problem that's specific to String#split.
  • String#split is lossy with regards to the original encoding of the string.

@dbussink
Copy link
Contributor

@leocassarani If we fix String#split, we can close this issue, since the remaining part is a duplicate of #1765

@dustalov
Copy link
Author

Yep. This issue mainly covers an encoding bug, not a multiple assignment problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants