Project

General

Profile

Bug #11324

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

Added by sakuro (Sakuro OZAWA) about 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Normal
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.

#2

Updated by nobu (Nobuyoshi Nakada) about 5 years ago

  • Status changed from Open to Closed

Applied in changeset r51116.


transcode.c: empty encoding name

  • transcode.c (rb_econv_set_replacement): target encoding name can be empty now. [ruby-core:69841] [Bug #11324]

Updated by nobu (Nobuyoshi Nakada) about 5 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED
#4

Updated by nagachika (Tomoyuki Chikanaga) almost 5 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE

Backported into ruby_2_2 branch at r51573.

#5

Updated by usa (Usaku NAKAMURA) almost 5 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE to 2.0.0: REQUIRED, 2.1: DONE, 2.2: DONE

ruby_2_1 r51614 merged revision(s) 51116.

Also available in: Atom PDF