Project

General

Profile

Actions

Bug #13874

closed

String#valid_encoding? has side effects

Added by ojundt (Oliver Jundt) over 7 years ago. Updated over 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
[ruby-core:82674]

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"

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #12431: Strange behavior of String#encode('UTF-8', 'UTF-8', ...) when the encoding of the source string is not UTF-8ClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0