This project is closed and read-only.
Actions
Backport #6190
closedString#encode return string containing invalid chars but marked as valid
Backport #6190:
String#encode return string containing invalid chars but marked as valid
Status:
Closed
Assignee:
Description
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:insqueeze' 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.
Actions