Skip to content

Commit

Permalink
Decode ByteList properly for toString
Browse files Browse the repository at this point in the history
This previously decoded the bytelist always as an ISO-8859-1
string, which would obviously break for other encodings and any
multibyte characters. This change uses the ByteList's Encoding's
actual Charset to decode the string.

Fixes jruby#909.
  • Loading branch information
headius committed Nov 22, 2024
1 parent dae3f9c commit 3c5bb2d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/util/ByteList.java
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,9 @@ public int hashCode() {
public String toString() {
String decoded = this.stringValue;
if (decoded == null) {
this.stringValue = decoded = decode(bytes, begin, realSize, ISO_LATIN_1);
Charset charset = this.encoding.getCharset();
if (charset == null) charset = ISO_LATIN_1;
this.stringValue = decoded = decode(bytes, begin, realSize, charset);
}
return decoded;
}
Expand Down

0 comments on commit 3c5bb2d

Please sign in to comment.