Project

General

Profile

Actions

Bug #11324

closed

Encoding to a String's own encoding with some options fails

Added by sakuro (Sakuro OZAWA) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
[ruby-core:69841]

Description

To encode a String instance to its own encoding seems to be a bad idea, but following result looks strange:

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0