Sha256: 2dbb257733a9cf7f2492d5a87757cba809c0651cb58c1dd996be37141866f8c1

Contents?: true

Size: 929 Bytes

Versions: 12

Compression:

Stored size: 929 Bytes

Contents

module ProxyPacRb
  # Encodes strings as UTF-8
  module Encoding
    if "".respond_to?(:encode)
      if RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'rbx'
        # workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588
        # workaround for rbx bug https://github.com/rubinius/rubinius/issues/1729
        def encode(string)
          if string.encoding.name == 'ASCII-8BIT'
            data = string.dup
            data.force_encoding('UTF-8')

            unless data.valid_encoding?
              fail ::Encoding::UndefinedConversionError, "Could not encode ASCII-8BIT data #{string.dump} as UTF-8"
            end
          else
            data = string.encode('UTF-8')
          end
          data
        end
      else
        def encode(string)
          string.encode('UTF-8')
        end
      end
    else
      # Define no-op on 1.8
      def encode(string)
        string
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
proxy_pac_rb-0.3.4 lib/proxy_pac_rb/encoding.rb
proxy_pac_rb-0.3.3 lib/proxy_pac_rb/encoding.rb
proxy_pac_rb-0.3.2 lib/proxy_pac_rb/encoding.rb
proxy_pac_rb-0.3.0 lib/proxy_pac_rb/encoding.rb
proxy_pac_rb-0.2.6 lib/proxy_pac_rb/encoding.rb
proxy_pac_rb-0.2.5 lib/proxy_pac_rb/encoding.rb
proxy_pac_rb-0.2.4 lib/proxy_pac_rb/encoding.rb
proxy_pac_rb-0.2.3 lib/proxy_pac_rb/encoding.rb
proxy_pac_rb-0.2.2 lib/proxy_pac_rb/encoding.rb
proxy_pac_rb-0.2.1 lib/proxy_pac_rb/encoding.rb
proxy_pac_rb-0.2.0 lib/proxy_pac_rb/encoding.rb
proxy_pac_rb-0.0.3 lib/proxy_pac_rb/encoding.rb