Skip to content

A method what is named with an encoding what is incompatible with Encoding.default_external causes crash #52

Closed

Description

@aycabta
  1. input define_method "a".encode(Encoding::UTF_16) do end and Enter on UTF-8 terminal env
  2. press Tab
  3. crash

Activity

  1. changed the title [-]A method what is named with an encoding what is different from `Encoding.default_external` causes crash[/-] [+]A method what is named with an encoding what is incompatible with `Encoding.default_external` causes crash[/+] on Jan 9, 2020
  2. added 8 commits that reference this issue on Oct 21, 2025
    1c50bc8
    2759a0a
    0550394
    795b975
    6ed23be
    a5d05eb
    b648d18
    84663b1
  3. eregon commented on Oct 27, 2025

    @eregon
    Member

    IMO it's unreasonable and pointless to define a method with a UTF-16 name, see truffleruby/truffleruby#4005 (comment).
    I think CRuby should actually prevent defining such a method in a dummy (Encoding::UTF_16) or ASCII-incompatible encoding (Encoding::UTF_16LE/Encoding::UTF_16BE).

  4. alexanderadam commented on Oct 27, 2025

    @alexanderadam
    Contributor

    I think CRuby should actually prevent defining such a method in a dummy (Encoding::UTF_16) or ASCII-incompatible encoding (Encoding::UTF_16LE/Encoding::UTF_16BE).

    What would you like to see?
    A particular exception thrown?

  5. added a commit that references this issue on Oct 27, 2025
    fed1886
  6. eregon commented on Oct 28, 2025

    @eregon
    Member

    All 3 UTF-16 encodings are ASCII-incompatible:

    irb(main):001> Encoding::UTF_16.ascii_compatible?
    => false
    irb(main):002> Encoding::UTF_16LE.ascii_compatible?
    => false
    irb(main):003> Encoding::UTF_16BE.ascii_compatible?
    => false
    

    And Ruby only supports sources in ASCII-compatible encodings:

    $ ruby -e '# encoding: utf-16le'
    -e:1: UTF-16LE is not ASCII compatible (ArgumentError)
    

    So I think either an ArgumentError or maybe Encoding::CompatibilityError when define_method receives a name in an ASCII-incompatible encoding.
    For example filesystem operations reject such ASCII-incompatible encodings:

    irb(main):004> File.read("abc".encode(Encoding::UTF_16LE))
    (irb):4:in `read': path name must be ASCII-compatible (UTF-16LE): "abc" (Encoding::CompatibilityError)
    	from (irb):4:in `<main>'
    	from <internal:kernel>:187:in `loop'
    	from /home/eregon/.rubies/ruby-3.3.5/lib/ruby/gems/3.3.0/gems/irb-1.13.1/exe/irb:9:in `<top (required)>'
    	from /home/eregon/.rubies/ruby-3.3.5/bin/irb:25:in `load'
    	from /home/eregon/.rubies/ruby-3.3.5/bin/irb:25:in `<main>'
    
  7. added a commit that references this issue on Oct 28, 2025
    18d152b
  8. added 3 commits that reference this issue on Oct 28, 2025
    53acae1
    078782c
    7af1008
  9. added 2 commits that reference this issue on Nov 19, 2025
    04fa9eb
    dfb89f2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions