Actions
Bug #13874
closedString#valid_encoding? has side effects
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
Backport:
Description
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.
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"
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0