Skip to content

encoding issue on MRI ruby #7

@net1957

Description

@net1957

on linux with MRI ruby 2.2.7-p470 i got encoding errors.

If you use a proxy file from a URL http://xxxxx/myproxy.pac it it returned as 'ASCII-8BIT' but it is really 'UTF-8' encoded. If you have some non ascii characters in the script it will fail.

I don't know if all servers have this issue or if it is related to excon gem (see excon/excon#606) or other code.

I see you have already some test for other ruby flavors.
I did simply use this monkey patch as a workaround:

# patch to correct utf8 string wrongly encoded as ASCII-8BIT
# tested on linux with ruby 2.2.7-p470
module ProxyPacRb
  # Encodes strings as UTF-8
  module Encoding
    def encode(string)
      if string.encoding.name == 'ASCII-8BIT'
        data = string.dup
        data.force_encoding('UTF-8')

        unless data.valid_encoding?
          raise ::Encoding::UndefinedConversionError, "Could not encode ASCII-8BIT data #{string.dump} as UTF-8"
        end
      else
        data = string.encode('UTF-8')
      end
      data
    end
  end
end

What do you think about that ? Have you better way to solve this ?

Regards

@maxmeyer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions