Skip to content

Fixes #6748. Inconsistent encoding when calling #to_s on arrays.#6759

Merged
enebo merged 2 commits intojruby:jruby-9.2from
enebo:fix_ary_to_s
Jul 26, 2021
Merged

Fixes #6748. Inconsistent encoding when calling #to_s on arrays.#6759
enebo merged 2 commits intojruby:jruby-9.2from
enebo:fix_ary_to_s

Conversation

@enebo
Copy link
Member

@enebo enebo commented Jul 22, 2021

The main problem with the original code was that we would:

    str.setEncoding(s.getEncoding());

Where s is an inspected element of the array. MRI will call
rb_enc_associate which may setEncoding but might not. In fact,
rb_enc_associate has a lot of logic which I don't really understand.
What I mean by that is that we call str.cat19 which will also do the
appropriate encoding negotiation of building up the result inspect
string. Why add this extra method into the mix?

I opted to just let cat19 do its thing and spec:ruby:fast passed.

A second change I made was to make the inspect string use default_external
unless it is an encoding which does not support ascii (which is needed since
inspect is adding ascii like '['). In the non-ascii case we just default to
US-ASCII. Thankfully spec/ruby already has specs for this.

enebo added 2 commits July 22, 2021 15:52
The main problem with the original code was that we would:

```java
    str.setEncoding(s.getEncoding());
```

Where s is an inspected element of the array.  MRI will call
rb_enc_associate which may setEncoding but might not.  In fact,
rb_enc_associate has a lot of logic which I don't really understand.
What I mean by that is that we call str.cat19 which will also do the
appropriate encoding negotiation of building up the result inspect
string.  Why add this extra method into the mix?

I opted to just let cat19 do its thing and spec:ruby:fast passed.

A second change I made was to make the inspect string use default_external
unless it is an encoding which does not support ascii (which is needed since
inspect is adding ascii like '[').  In the non-ascii case we just default to
US-ASCII.  Thankfully spec/ruby already has specs for this.
@enebo enebo added this to the JRuby 9.2.20.0 milestone Jul 26, 2021
@enebo enebo merged commit b42868f into jruby:jruby-9.2 Jul 26, 2021
@enebo enebo deleted the fix_ary_to_s branch March 4, 2025 18:35
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

Successfully merging this pull request may close these issues.

1 participant