class Honeybadger::Util::Sanitizer
Experimental RBS support (using type sampling data from the type_fusion project).
# sig/honeybadger/util/sanitizer.rbs class Honeybadger::Util::Sanitizer type Honeybadger__Util__Sanitizer_sanitize_data = Hash | Float | String | nil | true type Honeybadger__Util__Sanitizer_sanitize_return_value = String | nil | true | Float def self.sanitize: (Honeybadger__Util__Sanitizer_sanitize_data data, ?Integer depth, ?Set? stack, ?(Array[Symbol] | Array[]) parents) -> Honeybadger__Util__Sanitizer_sanitize_return_value type Honeybadger__Util__Sanitizer_basic_object?_object = true | String | Interrupt | Hash | nil | Float def basic_object?: (Honeybadger__Util__Sanitizer_basic_object?_object object) -> false def filter_key?: (Symbol key, ?Array[Symbol] parents) -> false def filters?: () -> false def initialize: (max_depth: Integer, filters: (Array[String] | Array[])) -> void def inspected?: (String string) -> nil type Honeybadger__Util__Sanitizer_recursive?_data = Hash | String | true | nil | Float def recursive?: (Honeybadger__Util__Sanitizer_recursive?_data data) -> bool type Honeybadger__Util__Sanitizer_sanitize_data = Hash | Float | String | nil | true type Honeybadger__Util__Sanitizer_sanitize_return_value = String | nil | true | Float def sanitize: (Honeybadger__Util__Sanitizer_sanitize_data data, ?Integer depth, ?Set? stack, ?(Array[Symbol] | Array[]) parents) -> Honeybadger__Util__Sanitizer_sanitize_return_value def sanitize_string: (String string) -> String def valid_encoding: (String string) -> String def valid_encoding?: (String string) -> true end
are based on Rails’ HTTP parameter filter.
Sanitizer sanitizes data for sending to Honeybadger’s API. The filters
def self.sanitize(data)
Experimental RBS support (using type sampling data from the type_fusion project).
type Honeybadger__Util__Sanitizer_sanitize_data = Hash | Float | String | nil | true type Honeybadger__Util__Sanitizer_sanitize_return_value = String | nil | true | Float type Honeybadger__Util__Sanitizer_sanitize_data = sql | String | name | String | duration | Float | Float | category | Symbol | message | String | metadata | severity | String | progname | NilClass | String | nil | severity | String | progname | NilClass | true | sql | String | name | String | cached | TrueClass | duration | Float | category | String | message | String | metadata | sql | String | name | String | cached | TrueClass | duration | Float | category | String | message | String | metadata | sql | String | name | String | duration | Float | category | String | message | String | metadata | identifier | String | layout | NilClass | locals | | cache_hit | NilClass | duration | Float def self.sanitize: (Honeybadger__Util__Sanitizer_sanitize_data data, ?Integer depth, ?Set? stack, ?( | Symbol) parents) -> Honeybadger__Util__Sanitizer_sanitize_return_value
This signature was generated using 523 samples from 1 application.
def self.sanitize(data) @sanitizer ||= new @sanitizer.sanitize(data) end
def basic_object?(object)
Experimental RBS support (using type sampling data from the type_fusion project).
type Honeybadger__Util__Sanitizer_basic_object?_object = true | String | Interrupt | Hash | nil | Float type Honeybadger__Util__Sanitizer_basic_object?_object = true | String | Interrupt | category | Symbol | message | String | metadata | severity | String | progname | NilClass | nil | sql | String | name | String | cached | TrueClass | duration | Float | category | String | message | String | metadata | sql | String | name | String | cached | TrueClass | duration | Float | Float | severity | String | progname | NilClass | category | String | message | String | metadata | sql | String | name | String | duration | Float | sql | String | name | String | duration | Float | | category | String | message | String | metadata | identifier | String | layout | NilClass | locals | | cache_hit | NilClass | duration | Float | date | Date | group | Group | min_height | String def basic_object?: (Honeybadger__Util__Sanitizer_basic_object?_object object) -> false
This signature was generated using 518 samples from 1 application.
def basic_object?(object) object.respond_to?(:to_s) false rescue # BasicObject doesn't respond to `#respond_to?`. true end
def can_dup?(obj)
def can_dup?(obj) !IMMUTABLE.any? {|k| obj.kind_of?(k) } end
def filter_cookies(raw_cookies)
def filter_cookies(raw_cookies) return raw_cookies unless filters? cookies = [] raw_cookies.to_s.split(COOKIE_PAIRS).each do |pair| name, values = pair.split(COOKIE_SEP, 2) values = FILTERED if filter_key?(name) cookies << "#{name}=#{values}" end cookies.join(COOKIE_PAIR_SEP) end
def filter_key?(key, parents = nil)
Experimental RBS support (using type sampling data from the type_fusion project).
def filter_key?: (Symbol key, ?( | Symbol) parents) -> false
This signature was generated using 412 samples from 1 application.
def filter_key?(key, parents = nil) return false unless filters? return true if regexps.any? { |r| key =~ r } return true if deep_regexps && parents && (joined = parents.join(".")) && deep_regexps.any? { |r| joined =~ r } false end
def filter_url(url)
def filter_url(url) return url unless filters? filtered_url = url.to_s.dup filtered_url.scan(/(?:^|&|\?)([^=?&]+)=([^&]+)/).each do |m| next unless filter_key?(m[0]) filtered_url.gsub!(/#{Regexp.escape(m[1])}/, FILTERED) end filtered_url end
def filters?
Experimental RBS support (using type sampling data from the type_fusion project).
def filters?: () -> false
This signature was generated using 459 samples from 1 application.
def filters? !!@filters end
def initialize(max_depth: 20, filters: [])
Experimental RBS support (using type sampling data from the type_fusion project).
def initialize: (max_depth: Integer, filters: (String | String | )) -> void
This signature was generated using 66 samples from 1 application.
def initialize(max_depth: 20, filters: []) @filters = !filters.empty? @max_depth = max_depth strings, @regexps, @blocks = [], [], [] filters.each do |item| case item when Proc @blocks << item when Regexp @regexps << item else strings << Regexp.escape(item.to_s) end end @deep_regexps, @regexps = @regexps.partition { |r| r.to_s.include?('\\.'.freeze) } deep_strings, @strings = strings.partition { |s| s.include?('\\.'.freeze) } @regexps << Regexp.new(strings.join('|'.freeze), true) unless strings.empty? @deep_regexps << Regexp.new(deep_strings.join('|'.freeze), true) unless deep_strings.empty? end
def inspected?(string)
Experimental RBS support (using type sampling data from the type_fusion project).
def inspected?: (String string) -> nil
This signature was generated using 5 samples from 1 application.
def inspected?(string) String(string) =~ /#<.*>/ end
def recursive?(data)
Experimental RBS support (using type sampling data from the type_fusion project).
type Honeybadger__Util__Sanitizer_recursive?_data = Hash | String | true | nil | Float type Honeybadger__Util__Sanitizer_recursive?_data = category | Symbol | message | String | metadata | severity | String | progname | NilClass | String | category | String | message | String | metadata | sql | String | name | NilClass | duration | Float | true | severity | String | progname | NilClass | nil | Float | category | String | message | String | metadata | sql | String | name | String | duration | Float | category | String | message | String | metadata | sql | String | name | String | cached | TrueClass | duration | Float | sql | String | name | String | cached | TrueClass | duration | Float | sql | String | name | String | duration | Float | date | Date | group | Group | min_height | String | | controller | String | action | String | format | Symbol | method | String | path | String | status | Integer | view_runtime | NilClass | db_runtime | Float | duration | Float | identifier | String | layout | NilClass | locals | date | Date | group | Group | min_height | String | cache_hit | NilClass | duration | Float | category | String | message | String | metadata | identifier | String | layout | NilClass | locals | date | Date | group | Group | min_height | String | cache_hit | NilClass | duration | Float | category | String | message | String | metadata | identifier | String | layout | NilClass | locals | absence_rule | AbsenceRule | cache_hit | NilClass | duration | Float def recursive?: (Honeybadger__Util__Sanitizer_recursive?_data data) -> bool
This signature was generated using 512 samples from 1 application.
def recursive?(data) data.is_a?(Hash) || data.is_a?(Array) || data.is_a?(Set) || data.respond_to?(:to_honeybadger) end
def sanitize(data, depth = 0, stack = nil, parents = [])
Experimental RBS support (using type sampling data from the type_fusion project).
type Honeybadger__Util__Sanitizer_sanitize_data = Hash | Float | String | nil | true type Honeybadger__Util__Sanitizer_sanitize_return_value = String | nil | true | Float type Honeybadger__Util__Sanitizer_sanitize_data = sql | String | name | String | duration | Float | Float | category | Symbol | message | String | metadata | severity | String | progname | NilClass | String | nil | severity | String | progname | NilClass | true | sql | String | name | String | cached | TrueClass | duration | Float | category | String | message | String | metadata | sql | String | name | String | cached | TrueClass | duration | Float | category | String | message | String | metadata | sql | String | name | String | duration | Float | category | String | message | String | metadata | identifier | String | layout | NilClass | locals | | cache_hit | NilClass | duration | Float def sanitize: (Honeybadger__Util__Sanitizer_sanitize_data data, ?Integer depth, ?Set? stack, ?( | Symbol) parents) -> Honeybadger__Util__Sanitizer_sanitize_return_value
This signature was generated using 523 samples from 1 application.
def sanitize(data, depth = 0, stack = nil, parents = []) return BASIC_OBJECT if basic_object?(data) if recursive?(data) return RECURSION if stack && stack.include?(data.object_id) stack = stack ? stack.dup : Set.new stack << data.object_id end case data when Hash return DEPTH if depth >= max_depth hash = data.to_hash new_hash = {} hash.each_pair do |key, value| parents.push(key) if deep_regexps key = key.kind_of?(Symbol) ? key : sanitize(key, depth+1, stack, parents) if filter_key?(key, parents) new_hash[key] = FILTERED else value = sanitize(value, depth+1, stack, parents) if blocks.any? && !recursive?(value) key = key.dup if can_dup?(key) value = value.dup if can_dup?(value) blocks.each { |b| b.call(key, value) } end new_hash[key] = value end parents.pop if deep_regexps end new_hash when Array, Set return DEPTH if depth >= max_depth data.to_a.map do |value| sanitize(value, depth+1, stack, parents) end when Numeric, TrueClass, FalseClass, NilClass data when String sanitize_string(data) when -> (d) { d.respond_to?(:to_honeybadger) } return DEPTH if depth >= max_depth begin data = data.to_honeybadger rescue return RAISED end sanitize(data, depth+1, stack, parents) else # all other objects klass = data.class begin data = String(data) rescue return RAISED end return "#<#{klass.name}>" if inspected?(data) sanitize_string(data) end end
def sanitize_string(string)
Experimental RBS support (using type sampling data from the type_fusion project).
def sanitize_string: (String string) -> String
This signature was generated using 263 samples from 1 application.
def sanitize_string(string) string = valid_encoding(string) return string unless string.respond_to?(:size) && string.size > MAX_STRING_SIZE string[0...MAX_STRING_SIZE] + TRUNCATED end
def valid_encoding(string)
Experimental RBS support (using type sampling data from the type_fusion project).
def valid_encoding: (String string) -> String
This signature was generated using 263 samples from 1 application.
def valid_encoding(string) return string if valid_encoding?(string) string.encode(Encoding::UTF_8, **ENCODE_OPTS) end
def valid_encoding?(string)
Experimental RBS support (using type sampling data from the type_fusion project).
def valid_encoding?: (String string) -> true
This signature was generated using 279 samples from 1 application.
def valid_encoding?(string) string.valid_encoding? && ( VALID_ENCODINGS.include?(string.encoding) || VALID_ENCODINGS.include?(Encoding.compatible?(''.freeze, string)) ) end