From: "naruse (Yui NARUSE)" Date: 2013-02-24T00:41:39+09:00 Subject: [ruby-core:52743] [Backport93 - Backport #6190][Assigned] String#encode return string containing invalid chars but marked as valid Issue #6190 has been updated by naruse (Yui NARUSE). Status changed from Closed to Assigned ---------------------------------------- Backport #6190: String#encode return string containing invalid chars but marked as valid https://bugs.ruby-lang.org/issues/6190#change-36833 Author: pplr (Pierre PLR) Status: Assigned Priority: Normal Assignee: Category: Target version: >> a = " \xE9 ".encode('UTF-8', 'UTF-8', :invalid => :replace, :replace => "?") >> a.valid_encoding? => true >> a => " \xE9 " >> a.squeeze ArgumentError: invalid byte sequence in UTF-8 from (irb):32:in `squeeze' from (irb):32 from /usr/bin/irb:12:in `
' The expected string is " ? ", as the documentation for the ":replace" options says : If the value is :replace, encode replaces invalid byte sequences in str with the replacement character. -- http://bugs.ruby-lang.org/