Sha256: 5d84d638146b702845f536af7f8144b598d1961dd677c4a6a4214881bccc3d7a

Contents?: true

Size: 822 Bytes

Versions: 25

Compression:

Stored size: 822 Bytes

Contents

module Honeybadger
  module Util
    class SQL
      ESCAPE_QUOTES = /(\\"|\\')/
      SQUOTE_DATA = /'(?:[^']|'')*'/
      DQUOTE_DATA = /"(?:[^"]|"")*"/
      NUMBER_DATA = /\b\d+\b/
      DOUBLE_QUOTERS = /(postgres|sqlite|postgis)/i

      def self.obfuscate(sql, adapter)
        force_utf_8(sql.to_s.dup).tap do |s|
          s.gsub!(/\s+/, " ")
          s.gsub!(ESCAPE_QUOTES, "".freeze)
          s.gsub!(SQUOTE_DATA, "'?'".freeze)
          s.gsub!(DQUOTE_DATA, '"?"'.freeze) unless adapter.to_s.match?(DOUBLE_QUOTERS)
          s.gsub!(NUMBER_DATA, "?".freeze)
          s.strip!
        end
      end

      def self.force_utf_8(string)
        string.encode(
          Encoding.find("UTF-8"),
          invalid: :replace,
          undef: :replace,
          replace: ""
        )
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
honeybadger-5.24.0 lib/honeybadger/util/sql.rb
honeybadger-5.23.0 lib/honeybadger/util/sql.rb
honeybadger-5.22.0 lib/honeybadger/util/sql.rb
honeybadger-5.21.0 lib/honeybadger/util/sql.rb
honeybadger-5.20.1 lib/honeybadger/util/sql.rb
honeybadger-5.20.0 lib/honeybadger/util/sql.rb
honeybadger-5.19.2 lib/honeybadger/util/sql.rb
honeybadger-5.19.1 lib/honeybadger/util/sql.rb
honeybadger-5.19.0 lib/honeybadger/util/sql.rb
honeybadger-5.18.0 lib/honeybadger/util/sql.rb
honeybadger-5.17.0 lib/honeybadger/util/sql.rb
honeybadger-5.16.0 lib/honeybadger/util/sql.rb
honeybadger-5.15.6 lib/honeybadger/util/sql.rb
honeybadger-5.15.5 lib/honeybadger/util/sql.rb
honeybadger-5.15.4 lib/honeybadger/util/sql.rb
honeybadger-5.15.3 lib/honeybadger/util/sql.rb
honeybadger-5.15.2 lib/honeybadger/util/sql.rb
honeybadger-5.15.1 lib/honeybadger/util/sql.rb
honeybadger-5.15.0 lib/honeybadger/util/sql.rb
honeybadger-5.14.2 lib/honeybadger/util/sql.rb