File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments