appsignal 0.12.beta.6 → 0.12.beta.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -12,11 +12,10 @@ module Appsignal
|
|
12
12
|
NUMERIC_DATA = /\b\d+\b/.freeze
|
13
13
|
SANITIZED_VALUE = '\1?\2'.freeze
|
14
14
|
|
15
|
-
attr_reader :adapter_uses_double_quoted_table_names
|
15
|
+
attr_reader :adapter_uses_double_quoted_table_names
|
16
16
|
|
17
17
|
def initialize
|
18
18
|
@connection_config = connection_config
|
19
|
-
@adapter_uses_prepared_statements = adapter_uses_prepared_statements?
|
20
19
|
@adapter_uses_double_quoted_table_names = adapter_uses_double_quoted_table_names?
|
21
20
|
rescue ::ActiveRecord::ConnectionNotEstablished
|
22
21
|
Appsignal::EventFormatter.unregister('sql.active_record', self.class)
|
@@ -25,22 +24,18 @@ module Appsignal
|
|
25
24
|
|
26
25
|
def format(payload)
|
27
26
|
return nil if schema_query?(payload) || !payload[:sql]
|
28
|
-
|
29
|
-
|
27
|
+
sql_string = payload[:sql].dup
|
28
|
+
if adapter_uses_double_quoted_table_names
|
29
|
+
sql_string.gsub!(SINGLE_QUOTE, SANITIZED_VALUE)
|
30
|
+
sql_string.gsub!(SINGLE_QUOTED_DATA, SANITIZED_VALUE)
|
30
31
|
else
|
31
|
-
sql_string
|
32
|
-
|
33
|
-
|
34
|
-
sql_string.gsub!(SINGLE_QUOTED_DATA, SANITIZED_VALUE)
|
35
|
-
else
|
36
|
-
sql_string.gsub!(SINGLE_QUOTE, SANITIZED_VALUE)
|
37
|
-
sql_string.gsub!(DOUBLE_QUOTE, SANITIZED_VALUE)
|
38
|
-
sql_string.gsub!(QUOTED_DATA, SANITIZED_VALUE)
|
39
|
-
end
|
40
|
-
sql_string.gsub!(IN_ARRAY, SANITIZED_VALUE)
|
41
|
-
sql_string.gsub!(NUMERIC_DATA, SANITIZED_VALUE)
|
42
|
-
[payload[:name], sql_string]
|
32
|
+
sql_string.gsub!(SINGLE_QUOTE, SANITIZED_VALUE)
|
33
|
+
sql_string.gsub!(DOUBLE_QUOTE, SANITIZED_VALUE)
|
34
|
+
sql_string.gsub!(QUOTED_DATA, SANITIZED_VALUE)
|
43
35
|
end
|
36
|
+
sql_string.gsub!(IN_ARRAY, SANITIZED_VALUE)
|
37
|
+
sql_string.gsub!(NUMERIC_DATA, SANITIZED_VALUE)
|
38
|
+
[payload[:name], sql_string]
|
44
39
|
end
|
45
40
|
|
46
41
|
protected
|
@@ -62,12 +57,6 @@ module Appsignal
|
|
62
57
|
adapter = @connection_config[:adapter]
|
63
58
|
adapter =~ /postgres/ || adapter =~ /sqlite/
|
64
59
|
end
|
65
|
-
|
66
|
-
def adapter_uses_prepared_statements?
|
67
|
-
return false unless adapter_uses_double_quoted_table_names?
|
68
|
-
return true if @connection_config[:prepared_statements].nil?
|
69
|
-
@connection_config[:prepared_statements]
|
70
|
-
end
|
71
60
|
end
|
72
61
|
end
|
73
62
|
end
|
data/lib/appsignal/version.rb
CHANGED
@@ -129,14 +129,6 @@ if rails_present?
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
context "skip sanitization for prepared statements" do
|
133
|
-
let(:connection_config) { {:adapter => 'postgresql'} }
|
134
|
-
|
135
|
-
let(:sql) { 'SELECT "table".* FROM "table" WHERE "id"=$1' }
|
136
|
-
|
137
|
-
it { should == ['Model load', 'SELECT "table".* FROM "table" WHERE "id"=$1'] }
|
138
|
-
end
|
139
|
-
|
140
132
|
context "return nil for schema queries" do
|
141
133
|
let(:name) { 'SCHEMA' }
|
142
134
|
let(:sql) { 'SET client_min_messages TO 22' }
|
@@ -193,28 +185,6 @@ if rails_present?
|
|
193
185
|
|
194
186
|
it { should be_true }
|
195
187
|
end
|
196
|
-
|
197
|
-
describe "adapter_uses_prepared_statements" do
|
198
|
-
subject { formatter.adapter_uses_prepared_statements }
|
199
|
-
|
200
|
-
context "when using mysql" do
|
201
|
-
let(:connection_config) { {:adapter => 'mysql'} }
|
202
|
-
|
203
|
-
it { should be_false }
|
204
|
-
end
|
205
|
-
|
206
|
-
context "when using postgresql" do
|
207
|
-
let(:connection_config) { {:adapter => 'postgresql'} }
|
208
|
-
|
209
|
-
it { should be_true }
|
210
|
-
end
|
211
|
-
|
212
|
-
context "when using postgresql and prepared statements is disabled" do
|
213
|
-
let(:connection_config) { {:adapter => 'postgresql', :prepared_statements => false} }
|
214
|
-
|
215
|
-
it { should be_false }
|
216
|
-
end
|
217
|
-
end
|
218
188
|
end
|
219
189
|
end
|
220
190
|
end
|