Sha256: 49903f88bdaea58b9f8ed115c29f623a8a2133e67619db8c576773d106fa9bc4

Contents?: true

Size: 1.41 KB

Versions: 38

Compression:

Stored size: 1.41 KB

Contents

module Appsignal
  module Utils
    # @api private
    class QueryParamsSanitizer
      REPLACEMENT_KEY = "?".freeze

      module ClassMethods
        def sanitize(params, only_top_level = false, key_sanitizer = nil)
          case params
          when Hash
            sanitize_hash params, only_top_level, key_sanitizer
          when Array
            sanitize_array params, only_top_level, key_sanitizer
          else
            REPLACEMENT_KEY
          end
        end

        private

        def sanitize_hash(hash, only_top_level, key_sanitizer)
          {}.tap do |h|
            hash.each do |key, value|
              h[sanitize_key(key, key_sanitizer)] =
                if only_top_level
                  REPLACEMENT_KEY
                else
                  sanitize(value, only_top_level, key_sanitizer)
                end
            end
          end
        end

        def sanitize_array(array, only_top_level, key_sanitizer)
          if only_top_level
            sanitize(array[0], only_top_level, key_sanitizer)
          else
            array.map do |value|
              sanitize(value, only_top_level, key_sanitizer)
            end.uniq
          end
        end

        def sanitize_key(key, sanitizer)
          case sanitizer
          when :mongodb then key.to_s.gsub(/(\..+)/, ".#{REPLACEMENT_KEY}")
          else key
          end
        end
      end

      extend ClassMethods
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
appsignal-2.5.3-java lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.3 lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.3.alpha.2 lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.3.alpha.2-java lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.3.alpha.1 lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.3.alpha.1-java lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.2-java lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.2 lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.1-java lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.1 lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.1.beta.1-java lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.1.beta.1 lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.0-java lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.0 lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.0.beta.1-java lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.0.beta.1 lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.0.alpha.1-java lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.5.0.alpha.1 lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.4.3 lib/appsignal/utils/query_params_sanitizer.rb
appsignal-2.4.2 lib/appsignal/utils/query_params_sanitizer.rb