From 3c5bb2dffe2df3e7a8656d0abc252410482dfbaf Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 24 Jun 2024 13:17:33 -0500 Subject: [PATCH] Decode ByteList properly for toString 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 #909. --- core/src/main/java/org/jruby/util/ByteList.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/jruby/util/ByteList.java b/core/src/main/java/org/jruby/util/ByteList.java index 1765e26c60a..fa01583dd8c 100644 --- a/core/src/main/java/org/jruby/util/ByteList.java +++ b/core/src/main/java/org/jruby/util/ByteList.java @@ -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; }