Sha256: 1e739a6f13a47893817790509085aca2bb58395936b7a47ceccc68b8e297f108
Contents?: true
Size: 658 Bytes
Versions: 19
Compression:
Stored size: 658 Bytes
Contents
# typed: true # Copyright (c) 2015 Sqreen. All Rights Reserved. # Please refer to our terms for more information: https://www.sqreen.com/terms.html module Sqreen class EncodingSanitizer def self.sanitize(obj) case obj when String sanitize_string(obj) when Array obj.map { |e| sanitize(e) } when Hash obj.each_with_object({}) { |(k, v), h| h[k] = sanitize(v) } else obj end end def self.sanitize_string(s) return s if s.encoding.name == 'UTF-8' && s.valid_encoding? s.encode('UTF-16', :invalid => :replace, :undef => :replace).encode('UTF-8') end end end
Version data entries
19 entries across 19 versions & 1 rubygems