New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ahorek opened this Issue May 10, 2016 · 6 comments

Comments

Projects
None yet
2 participants
@ahorek
Contributor

ahorek commented May 10, 2016

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;
}
@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius May 10, 2016

Member

We can probably bind these few methods, but we don't have a compile time for it (and I expect ArgFileApisANSI is a compiler macro). What does MRI produce for filesystem encoding on your system?

@ahorek Does the output of ENV_JAVA['file.encoding'] match what you would expect from the filesystem Encoding in Ruby?

Member

headius commented May 10, 2016

We can probably bind these few methods, but we don't have a compile time for it (and I expect ArgFileApisANSI is a compiler macro). What does MRI produce for filesystem encoding on your system?

@ahorek Does the output of ENV_JAVA['file.encoding'] match what you would expect from the filesystem Encoding in Ruby?

@ahorek

This comment has been minimized.

Show comment
Hide comment
@ahorek

ahorek May 10, 2016

Contributor
irb(main):034:0> ENV_JAVA['file.encoding']
=> "Cp1252"

or

irb(main):033:0>  java.nio.charset.Charset.defaultCharset.to_s
=> "windows-1252"
    private static Charset getDefaultCharset() {
        String encoding = System.getProperty("file.encoding", "UTF-8");
        try {
            return Charset.forName(encoding);
        } catch (UnsupportedCharsetException e) {
            return Charset.forName("UTF-8");
        }
    }

it matches, but I don't know how safe that is.

Contributor

ahorek commented May 10, 2016

irb(main):034:0> ENV_JAVA['file.encoding']
=> "Cp1252"

or

irb(main):033:0>  java.nio.charset.Charset.defaultCharset.to_s
=> "windows-1252"
    private static Charset getDefaultCharset() {
        String encoding = System.getProperty("file.encoding", "UTF-8");
        try {
            return Charset.forName(encoding);
        } catch (UnsupportedCharsetException e) {
            return Charset.forName("UTF-8");
        }
    }

it matches, but I don't know how safe that is.

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius May 10, 2016

Member

Does it match what MRI reports?

Member

headius commented May 10, 2016

Does it match what MRI reports?

@ahorek

This comment has been minimized.

Show comment
Hide comment
@ahorek

ahorek May 10, 2016

Contributor

yes

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

ahorek commented May 10, 2016

yes

irb(main):007:0> Encoding.find("filesystem")
=> #<Encoding:Windows-1252>
@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius May 10, 2016

Member

@ahorek Seems like a quick fix then would be for us to use the default charset or file.encoding for the filesystem encoding on Windows.

Member

headius commented May 10, 2016

@ahorek Seems like a quick fix then would be for us to use the default charset or file.encoding for the filesystem encoding on Windows.

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius May 11, 2016

Member

@ahorek I have committed a change to try to use the value set for file.encoding as the "filesystem" encoding. Please confirm it resolves your issues.

Could you please add a spec for this to https://github.com/ruby/spec, or otherwise a spec for our regression suite under spec/regression?

Member

headius commented May 11, 2016

@ahorek I have committed a change to try to use the value set for file.encoding as the "filesystem" encoding. Please confirm it resolves your issues.

Could you please add a spec for this to https://github.com/ruby/spec, or otherwise a spec for our regression suite under spec/regression?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment