Project

General

Profile

Bug #13874

Updated by ojundt (Oliver Jundt) over 7 years ago

I noticed the result of `String#encode` changes after a call to `String#valid_encoding?`. Other side effects were not visible so far. 

 Based on the documentation and intuition I would expect `#valid_encoding?` to be an operation without side effects. 

 ~~~ ruby 
 content = "\xE5".dup.force_encoding(Encoding::ASCII_8BIT) 

 p content.encode(Encoding::UTF_8, Encoding::UTF_8, invalid: :replace, undef: :replace, replace: '?') 
 => "?" 

 content.valid_encoding? 

 p content.encode(Encoding::UTF_8, Encoding::UTF_8, invalid: :replace, undef: :replace, replace: '?') 
 => "\xE5" 
 ~~~

Back