Class: Honeybadger::Util::SQL Private

Inherits:
Object
  • Object
show all
Defined in:
lib/honeybadger/util/sql.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

ESCAPE_QUOTES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/(\\"|\\')/
SQUOTE_DATA =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/'(?:[^']|'')*'/
DQUOTE_DATA =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/"(?:[^"]|"")*"/
NUMBER_DATA =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/\b\d+\b/
DOUBLE_QUOTERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/(postgres|sqlite|postgis)/i

Class Method Summary collapse

Class Method Details

.force_utf_8(string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
27
28
# File 'lib/honeybadger/util/sql.rb', line 21

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

.obfuscate(sql, adapter) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
14
15
16
17
18
19
# File 'lib/honeybadger/util/sql.rb', line 10

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