Skip to content

buffer encoding issues #18

Description

@HoneyryderChuck

I've been seeing some issues with this gem in jruby, that led me to this snippet here, where I think that some encoding mis-handling might be happening, and wanted to open the discussion before a PR is submitted.

The snippet in question was (in my case) "shadowed" by IO.copy_stream, but the gist of it is:

  • outbuf.to_s.replace("") will return an "UTF-8" string.
  • @bufferis a binary string.
  • outbuf << @buffer will not change the encoding in outbuf (it'll remain "UTF-8").
  • @buffer.length != @buffer.bytesize

I'd like to propose the following changes:

  • all strings (outbuf, @buffer) should be binary (current_io.read(length, @buffer)would anyways convert the buffer to binary if it were another encoding).
  • switch to @buffer.bytesize;
  • switch to use "".b for initialization (because String.new.encoding, String.new("").encoding...).

Activity

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