Project

General

Profile

Actions

Feature #22244

open

`ruby -UU` should set both internal and external, `ruby -E` should print encoding list

Feature #22244: `ruby -UU` should set both internal and external, `ruby -E` should print encoding list

Added by zenspider (Ryan Davis) 4 months ago. Updated 23 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:126381]

Description

10004 $ env -u LANG ruby -U -e 'pp [Encoding.default_internal, Encoding.default_external]'
[#<Encoding:UTF-8>, #<Encoding:US-ASCII>]

10005 $ env -u LANG ruby -EUTF-8 -e 'pp [...]'
[nil, #<Encoding:UTF-8>]

10006 $ env -u LANG ruby -EUTF-8 -U -e 'pp [...]'
[#<Encoding:UTF-8>, #<Encoding:UTF-8>]

10007 $ env -u LANG ruby -EUTF-8:UTF-8 -e 'pp [...]'
[#<Encoding:UTF-8>, #<Encoding:UTF-8>]

10008 $ env -u LANG ruby -UU -e 'pp [...]'
[#<Encoding:UTF-8>, #<Encoding:US-ASCII>]

I think the option processing of encodings is VERY poorly documented and frustrating to try to use.

  1. --help doesn't list -U. (The man page does)
  2. --help for -E doesn't provide a means to get a list of available encoding names (same with manpage), leading me to try U, UTF8, UTF_8, before finding UTF-8. ruby -E could just print them all out.
  3. WHY NOT take UTF8 or UTF_8 (since that's the class name)?
  4. Please consider -UU to mean -EUTF-8:UTF-8

Updated by zenspider (Ryan Davis) 4 months ago Actions #1 [ruby-core:126385]

Quick and dirty patch: https://github.com/ruby/ruby/compare/master...zenspider:ruby:zenspider__encodings?expand=1

This is rough. I'm faking an eval early in the option handling. There is probably a better C way to do this. It is probably failing tests.

But the idea is there.

Updated by zenspider (Ryan Davis) about 2 months ago Actions #3 [ruby-core:127064]

This is all greened up. Sorry for taking so long!

Updated by zenspider (Ryan Davis) about 2 months ago Actions #4 [ruby-core:127129]

@matz (Yukihiro Matsumoto) any chance I can get this enhancement into 4.1? I think it helps usability a fair amount:

10001 $ ./build/miniruby tool/runruby.rb --extout=build --archdir=build  -- -E
Available Encodings:

    ASCII-8BIT, Big5, Big5-HKSCS, Big5-UAO, CESU-8, CP850, CP852, CP855,
    CP949, CP950, CP951, CP50220, CP50221, CP51932, Emacs-Mule, EUC-JIS-2004,
    EUC-JP, EUC-KR, EUC-TW, eucJP-ms, GB1988, GB2312, GB12345, GB18030, GBK,
    IBM037, IBM437, IBM720, IBM737, IBM775, IBM852, IBM855, IBM857, IBM860,
    IBM861, IBM862, IBM863, IBM864, IBM865, IBM866, IBM869, ISO-2022-JP,
    ISO-2022-JP-2, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4,
    ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-10,
    ISO-8859-11, ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16, KOI8-R,
    KOI8-U, macCentEuro, macCroatian, macCyrillic, macGreek, macIceland,
    MacJapanese, macRoman, macRomania, macThai, macTurkish, macUkraine,
    Shift_JIS, TIS-620, US-ASCII, UTF8-MAC, UTF-7, UTF-8, UTF-16, UTF-16BE,
    UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, Windows-31J, Windows-874,
    Windows-1250, Windows-1251, Windows-1252, Windows-1253, Windows-1254,
    Windows-1255, Windows-1256, Windows-1257, Windows-1258

Updated by Anonymous about 2 months ago Actions #5

Hello Ryan,

I suggest you add your issue to [Ruby Misc#22417] DevMeeting-2026-11-12.
This is the best way to get attention and a decision from @matz (Yukihiro Matsumoto).

Regards, Martin.

On 2026-10-16 04:00, zenspider (Ryan Davis) via ruby-core wrote:

Issue #22244 has been updated by zenspider (Ryan Davis).

@matz (Yukihiro Matsumoto) any chance I can get this enhancement into 4.1? I think it helps usability a fair amount:

10001 $ ./build/miniruby tool/runruby.rb --extout=build --archdir=build  -- -E
Available Encodings:

     ASCII-8BIT, Big5, Big5-HKSCS, Big5-UAO, CESU-8, CP850, CP852, CP855,
     CP949, CP950, CP951, CP50220, CP50221, CP51932, Emacs-Mule, EUC-JIS-2004,
     EUC-JP, EUC-KR, EUC-TW, eucJP-ms, GB1988, GB2312, GB12345, GB18030, GBK,
     IBM037, IBM437, IBM720, IBM737, IBM775, IBM852, IBM855, IBM857, IBM860,
     IBM861, IBM862, IBM863, IBM864, IBM865, IBM866, IBM869, ISO-2022-JP,
     ISO-2022-JP-2, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4,
     ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-10,
     ISO-8859-11, ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16, KOI8-R,
     KOI8-U, macCentEuro, macCroatian, macCyrillic, macGreek, macIceland,
     MacJapanese, macRoman, macRomania, macThai, macTurkish, macUkraine,
     Shift_JIS, TIS-620, US-ASCII, UTF8-MAC, UTF-7, UTF-8, UTF-16, UTF-16BE,
     UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, Windows-31J, Windows-874,
     Windows-1250, Windows-1251, Windows-1252, Windows-1253, Windows-1254,
     Windows-1255, Windows-1256, Windows-1257, Windows-1258

Feature #22244: ruby -UU should set both internal and external, ruby -E should print encoding list
https://bugs.ruby-lang.org/issues/22244#change-119533

  • Author: zenspider (Ryan Davis)
  • Status: Open

10004 $ env -u LANG ruby -U -e 'pp [Encoding.default_internal, Encoding.default_external]'
[#<Encoding:UTF-8>, #<Encoding:US-ASCII>]

10005 $ env -u LANG ruby -EUTF-8 -e 'pp [...]'
[nil, #<Encoding:UTF-8>]

10006 $ env -u LANG ruby -EUTF-8 -U -e 'pp [...]'
[#<Encoding:UTF-8>, #<Encoding:UTF-8>]

10007 $ env -u LANG ruby -EUTF-8:UTF-8 -e 'pp [...]'
[#<Encoding:UTF-8>, #<Encoding:UTF-8>]

10008 $ env -u LANG ruby -UU -e 'pp [...]'
[#<Encoding:UTF-8>, #<Encoding:US-ASCII>]

I think the option processing of encodings is VERY poorly documented and frustrating to try to use.

  1. --help doesn't list -U. (The man page does)
  2. --help for -E doesn't provide a means to get a list of available encoding names (same with manpage), leading me to try U, UTF8, UTF_8, before finding UTF-8. ruby -E could just print them all out.
  3. WHY NOT take UTF8 or UTF_8 (since that's the class name)?
  4. Please consider -UU to mean -EUTF-8:UTF-8

Updated by naruse (Yui NARUSE) 26 days ago 1Actions #6 [ruby-core:127402]

I'm not sure about a situation you emulate with env -u LANG.

--help doesn't list -U. (The man page does)

Usually with LANG environment variable, it is automatically set.
Another reason is that matz says --help should be shown in 1 page.

--help for -E doesn't provide a means to get a list of available encoding names (same with manpage), leading me to try U, UTF8, UTF_8, before finding UTF-8. ruby -E could just print them all out.

If you set LANG environment variable correctly for example LANG=en_US.UTF-8, you don't need to use -U and -E.
I don't think there is a reason to recommendd such an indirect approach.

WHY NOT take UTF8 or UTF_8 (since that's the class name)?

UTF-8 is the canonical name of the IANA charset.
LANG environment variable also accept for example en_US.UTF-8.
If you have a certain situation or context when ruby should accept UTF8 or UTF_8, they are added as an alias.

Please consider -UU to mean -EUTF-8:UTF-8

internal encoding is for automatic encoding conversion.
It introduces another complexity for an application.
Usually modern application should be design without encoding conversion.
Therefore I don't think there is enough needs for adding -UU.

Updated by matz (Yukihiro Matsumoto) 23 days ago Actions #7 [ruby-core:127463]

For now, I agree with @naruse (Yui NARUSE). The internal encoding is for automatic conversion, and setting LANG properly is the recommended way, so I don't see the need for -UU to set both.

For the other points, Encoding.name_list already gives the list of encodings, and I'd like to keep --help within one page.

That said, I may reconsider -UU if you can describe in detail the cases where the change is really useful, for example, environments or circumstances where LANG cannot be set.

Matz.

Actions

Also available in: PDF Atom