Skip to content

Encoding.find("filesystem") on windows #3871

@ahorek

Description

@ahorek

Environment

jruby 9.1.0.0 (2.3.0) 2016-05-02 a633c63 Java HotSpot(TM) 64-Bit Server VM 25.92-b14 on 1.8.0_92-b14 +jit [mswin32-x86_64]

Expected Behavior

mri

irb(main):007:0> Encoding.find("filesystem")
=> #<Encoding:Windows-1252>
irb(main):008:0> Encoding.default_external
=> #<Encoding:IBM852>

Actual Behavior

jruby

irb(main):023:0> Encoding.find("filesystem")
=> #<Encoding:IBM852>
irb(main):024:0> Encoding.default_external
=> #<Encoding:IBM852>

it looks like Encoding.find("filesystem") is just an alias to Encoding.default_external

            case FILESYSTEM:
                // This needs to do something different on Windows. See encoding.c,
                // in the enc_set_filesystem_encoding function.
                return runtime.getDefaultExternalEncoding();

https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/runtime/encoding/EncodingService.java#L545

for windows the mri's logic is a little bit different

int Init_enc_set_filesystem_encoding(void)
{
    int idx;
#if defined NO_LOCALE_CHARMAP
# error NO_LOCALE_CHARMAP defined
#elif defined _WIN32 || defined __CYGWIN__
    char cp[SIZEOF_CP_NAME];
    CP_FORMAT(cp, AreFileApisANSI() ? GetACP() : GetOEMCP());
    idx = rb_enc_find_index(cp);
    if (idx < 0) idx = ENCINDEX_ASCII;
#else
    idx = rb_enc_to_index(rb_default_external_encoding());
#endif
    return idx;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions