[ruby-core:69841] [Ruby trunk - Bug #11324] [Open] Encoding to a String's own encoding with some options fails

From: redmine.ruby-lang.org@2238club.org
Date: 2015-07-02 08:20:31 UTC
List: ruby-core #69841
Issue #11324 has been reported by Sakuro OZAWA.

----------------------------------------
Bug #11324: Encoding to a String's own encoding with some options fails
https://bugs.ruby-lang.org/issues/11324

* Author: Sakuro OZAWA
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
To encode a `String` instance to its own encoding seems to be a bad idea, but following result looks strange:

```ruby
s = "A\nB\r\nC".force_encoding('US-ASCII')
#=> "A\nB\r\nC"
s.encode('US-ASCII')
#=> "A\nB\r\nC"
s.encode('US-ASCII', universal_newline: true)
#=> "A\nB\nC"
s.encode('US-ASCII', universal_newline: true, undef: :replace)
#=> "A\nB\nC"
s.encode('US-ASCII', universal_newline: true, undef: :replace, replace: '')
# Encoding::ConverterNotFoundError: code converter not found (universal_newline)
```

Only when all of these three options are fed, `String#encode` fails and provided message shows unclear encoding name.





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

In This Thread

Prev Next