Skip to content

RubyIO.getOutputStream incompatible with external encoding #6588

@headius

Description

@headius

The OutputStream implementation returned by RubyIO.getOutputStream always treats incoming bytes as being ASCII-8BIT encoding. This breaks writes when the underlying RubyIO has been initialized with an incompatible external encoding, like UTF-8.

@Override
public void write(byte[] b) throws IOException {
RubyIO.this.write(runtime.getCurrentContext(), RubyString.newStringNoCopy(runtime, b));
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
RubyIO.this.write(runtime.getCurrentContext(), RubyString.newStringNoCopy(runtime, b, off, len));
}

This led to one failure in the Psych tests as noted in ruby/psych#481 and fixed by #6587.

I believe this stream should handle the encoding better using one of these options (perhaps?):

  • Assume the bytes are encoded like the IO's internal encoding, which may be the default UTF-8 of Ruby. The bytes will be transcoded to whatever the external encoding is supposed to be.
  • Assume the bytes are encoded like the IO's external encoding. They will be written directly without any transcoding (or any verification that they are in that encoding).

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