Project

General

Profile

Bug #5862

Strings not encoded in -E encoding

Added by brixen (Brian Shirai) almost 8 years ago. Updated almost 8 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
Backport:
[ruby-core:41970]

Description

If I pass the -E option, the Encoding.default_external is set to that encoding, but the string in the -e code is not set to that encoding, nor is the value of ENCODING set to it.

$ ruby -v -E ascii-8bit -e 'p "abc".encoding, Encoding.default_external, Encoding.default_internal, ENCODING'
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
#Encoding:UTF-8
#Encoding:ASCII-8BIT
nil
#Encoding:UTF-8

However, if I pass -Ka, the encodings for all of 1. Encoding.default_external, 2. the -e string literal, and 3. ENCODING in -e code are set to eg ASCII-8BIT.

$ ruby -v -Ka -e 'p "abc".encoding, Encoding.default_external, Encoding.default_internal, ENCODING'
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
#Encoding:ASCII-8BIT
#Encoding:ASCII-8BIT
nil
#Encoding:ASCII-8BIT

If -E {enc} sets Encoding.default_external to {enc} and data read from IO streams is set to encoding Encoding.default_external, and STDIO is an IO stream, shouldn't passing -E {enc} cause the -e string literal to have encoding {enc}? If not, could someone please explain the exact semantics of these two different command line options.

Thanks,
Brian

History

Updated by nobu (Nobuyoshi Nakada) almost 8 years ago

  • Status changed from Open to Rejected
  • Category set to M17N

=begin

Ruby has three types of default encodings, internal, external, and
source-code (which (({ENCODING})) equals to), and they are
independent each others. (({-E})) option sets the former two, but
does nothing for source-code encoding.

If you want to set source-code encoding in (({-e})), try:

$ ruby -e'#encoding:ascii-8bit' -e 'p ENCODING'

=end

Updated by brixen (Brian Shirai) almost 8 years ago

Just to be clear, the -K options do set the source-code encoding, right?

Thanks,
Brian

Updated by nobu (Nobuyoshi Nakada) almost 8 years ago

Brian Ford wrote:

Just to be clear, the -K options do set the source-code encoding, right?

Yes, it sets all of three.
Sorry that I forgot to mention about it.

Updated by naruse (Yui NARUSE) almost 8 years ago

When we design the system, -e is used through a console (terminal emulator).
So -e follows the consoles's encoding, and it is assumed to be the locale encoding.
So -E doesn't effect.

-K intends for compatibility.
It effects all encodings except default internal.

Also available in: Atom PDF