From: zverok.offline@... Date: 2019-12-14T19:13:59+00:00 Subject: [ruby-core:96239] [Ruby master Bug#16422] IO#set_encoding_by_bom when encoding is already set Issue #16422 has been reported by zverok (Victor Shepelev). ---------------------------------------- Bug #16422: IO#set_encoding_by_bom when encoding is already set https://bugs.ruby-lang.org/issues/16422 * Author: zverok (Victor Shepelev) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- `IO#set_encoding_by_bom` docs [say](https://ruby-doc.org/core-2.7.0.preview3/IO.html#method-i-set_encoding_by_bom): > If ios is not binmode or **its encoding has been set already**, an exception will be raised. In reality this does not happen (or I don't understand the meaning of bold statement above): ```ruby File.write("tmp/bom.txt", "\u{FEFF}��������") ios = File.open("tmp/bom.txt", "rb", encoding: 'Windows-1251') ios.external_encoding # => # ios.set_encoding_by_bom # => # ios.external_encoding # => # ``` ...though [in code](https://github.com/ruby/ruby/blob/master/io.c#L8334), seems that error _should_ be raised. I wonder if it is an error in docs, bug in code, or just my misunderstanding?.. -- https://bugs.ruby-lang.org/ Unsubscribe: