Skip to content

Commit 36d4d75

Browse files
authored
Merge pull request #73 from travis-ci/igor-sql
improved sql comment handling
2 parents a61ac25 + 05e27f5 commit 36d4d75

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

lib/marginalia/comment.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ def self.construct_comment
2626
end
2727
end
2828
ret.chop!
29+
ret = self.escape_sql_comment(ret)
2930
ret
3031
end
3132

33+
def self.escape_sql_comment(str)
34+
while str.include?('/*') || str.include?('*/')
35+
str = str.gsub('/*', '').gsub('*/', '')
36+
end
37+
str
38+
end
39+
3240
def self.clear!
3341
self.marginalia_controller = nil
3442
end

test/query_comments_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ def test_active_job
272272
end
273273
end
274274

275+
def test_good_comment
276+
assert_equal Marginalia::Comment.escape_sql_comment('app:foo'), 'app:foo'
277+
end
278+
279+
def test_bad_comments
280+
assert_equal Marginalia::Comment.escape_sql_comment('*/; DROP TABLE USERS;/*'), '; DROP TABLE USERS;'
281+
assert_equal Marginalia::Comment.escape_sql_comment('**//; DROP TABLE USERS;/*'), '; DROP TABLE USERS;'
282+
end
283+
275284
def teardown
276285
Marginalia.application_name = nil
277286
Marginalia::Comment.lines_to_ignore = nil

0 commit comments

Comments
 (0)