Sha256: 248a062b3d6752048bfa75acebf5c2a14580bc22edcacd57c2d04e744374bc87
Contents?: true
Size: 643 Bytes
Versions: 12
Compression:
Stored size: 643 Bytes
Contents
# 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
12 entries across 12 versions & 1 rubygems