Issue #13874 has been updated by ojundt (Oliver Jundt).


Also reproducible on `ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]` 

Not reproducible on `ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-linux]`. Both calls result in `"\xE5"`



----------------------------------------
Bug #13874: String#valid_encoding? has side effects
https://bugs.ruby-lang.org/issues/13874#change-66507

* Author: ojundt (Oliver Jundt)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
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)

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

content.valid_encoding?

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



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>