Project

General

Profile

Actions

Backport #6190

closed

String#encode return string containing invalid chars but marked as valid

Added by pplr (Pierre PLR) almost 13 years ago. Updated over 11 years ago.

Status:
Closed
[ruby-core:43557]

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: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.


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #19342: String#encode does not always throw exceptions for invalid source encodingsClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0