[ruby-core:96239] [Ruby master Bug#16422] IO#set_encoding_by_bom when encoding is already set

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.issue-16422.20191214191358.9ea1e0908f83f19b@ruby-lang.org>
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
# => #<Encoding:Windows-1251>
ios.set_encoding_by_bom
# => #<Encoding:UTF-8>
ios.external_encoding
# => #<Encoding:UTF-8>
```
...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: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.