From: merch-redmine@... Date: 2021-06-25T20:09:01+00:00 Subject: [ruby-dev:51071] [Ruby master Bug#12052] String#encode with xml option returns wrong result for totally non-ASCII-compatible encodings Issue #12052 has been updated by jeremyevans0 (Jeremy Evans). jeremyevans0 (Jeremy Evans) wrote in #note-3: > So a possible way to work around the issue until it can be properly fixed would be to detect the case where both source and destination are multibyte, switch the destination to UTF-8, then encode the result of that to the desired destination encoding. I've submitted a patch that does this, and confirmed it fixes this issue: https://github.com/ruby/ruby/pull/4605 ---------------------------------------- Bug #12052: String#encode with xml option returns wrong result for totally non-ASCII-compatible encodings https://bugs.ruby-lang.org/issues/12052#change-92652 * Author: nobu (Nobuyoshi Nakada) * Status: Open * Priority: Normal * Assignee: akr (Akira Tanaka) * Backport: 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED ---------------------------------------- `String#encode`をASCII非互換エンコーディングから同じエンコーディングへ、`xml:`オプション付きで呼ぶとおかしな結果を返します。 バイナリとして変換してしまっているようです。 ```ruby p "<\0>\0".encode("utf-16le", "utf-16le", xml: :text) #=> "\u6C26\u3B74\u2600\u7467;" ``` -- https://bugs.ruby-lang.org/