Sha256: 1b11586dd4b25f437e7deadae1f74a942d6445cf49447288ca06ade61a6d1460

Contents?: true

Size: 463 Bytes

Versions: 1

Compression:

Stored size: 463 Bytes

Contents

module PactBroker
  module Api
    module Contracts
      module UTF8Validation
        def fragment_before_invalid_utf_8_char(string)
          string.force_encoding("UTF-8").each_char.with_index do | char, index |
            if !char.valid_encoding?
              fragment = index < 100 ? string[0...index] : string[index-100...index]
              return index + 1, fragment
            end
          end
          nil
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact_broker-2.106.0 lib/pact_broker/api/contracts/utf_8_validation.rb