From 7aa87aa446261deee29864008ee024aa18dd7b2c Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Fri, 21 Jun 2019 16:25:26 -0400 Subject: [PATCH 1/2] Support multi-line values --- lib/sql_footprint/sql_anonymizer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sql_footprint/sql_anonymizer.rb b/lib/sql_footprint/sql_anonymizer.rb index 10137ed..cf56156 100644 --- a/lib/sql_footprint/sql_anonymizer.rb +++ b/lib/sql_footprint/sql_anonymizer.rb @@ -5,7 +5,7 @@ class SqlAnonymizer /([\s\(])'.*'/ => "\\1'value-redacted'".freeze, # literal strings /N''.*''/ => "N''value-redacted''".freeze, # literal MSSQL strings /\s+(!=|=|<|>|<=|>=)\s+[0-9]+/ => ' \1 number-redacted'.freeze, # numbers - /\s+VALUES\s+\(.+\)/ => ' VALUES (values-redacted)'.freeze, # VALUES + /\s+VALUES\s+\(.*?\)/m => ' VALUES (values-redacted)'.freeze, # VALUES } def anonymize sql From 7c69559d9869f830323cd67a3c45656f5e44aafa Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Mon, 24 Jun 2019 14:24:45 -0400 Subject: [PATCH 2/2] Add spec --- spec/sql_footprint/sql_anonymizer_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/sql_footprint/sql_anonymizer_spec.rb b/spec/sql_footprint/sql_anonymizer_spec.rb index e2d113e..9e61931 100644 --- a/spec/sql_footprint/sql_anonymizer_spec.rb +++ b/spec/sql_footprint/sql_anonymizer_spec.rb @@ -66,6 +66,13 @@ ) end + it 'handles multi-line VALUES' do + sql = 'INSERT INTO "widgets" ("created_at", "name") VALUES ' \ + "('2016-05-1 6 19:16:04.981048', 'asdf\nasdf') RETURNING \"id\"" + expect(anonymizer.anonymize(sql)).to eq 'INSERT INTO "widgets" ' \ + '("created_at", "name") VALUES (values-redacted) RETURNING "id"' + end + context 'with a custom rule' do let(:redacted) { 'SELECT [redacted] AS [redacted]'.freeze }