File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 1+ * [ #1553 ] ( https://github.com/rubocop/rubocop-rails/issues/1553 ) : Fix false positives for ` Rails/OutputSafety ` when using non-interpolated multiline heredoc. ([ @koic ] [ ] )
Original file line number Diff line number Diff line change @@ -84,7 +84,9 @@ def on_send(node)
8484 private
8585
8686 def non_interpolated_string? ( node )
87- node . receiver &.str_type? && !node . receiver . dstr_type?
87+ return false unless ( receiver = node . receiver )
88+
89+ receiver . str_type? || ( receiver . dstr_type? && receiver . children . all? ( &:str_type? ) )
8890 end
8991
9092 def looks_like_rails_html_safe? ( node )
Original file line number Diff line number Diff line change 4040 RUBY
4141 end
4242
43+ it 'does not register an offense for static single line heredoc receiver' do
44+ expect_no_offenses ( <<~RUBY )
45+ <<~HTML.html_safe
46+ foo
47+ HTML
48+ RUBY
49+ end
50+
51+ it 'registers an offense for dynamic single line heredoc receiver' do
52+ expect_offense ( <<~'RUBY' )
53+ <<~HTML.html_safe
54+ ^^^^^^^^^ Tagging a string as html safe may be a security risk.
55+ #{foo}
56+ HTML
57+ RUBY
58+ end
59+
60+ it 'does not register an offense for static multiline heredoc receiver' do
61+ expect_no_offenses ( <<~RUBY )
62+ <<~HTML.html_safe
63+ foo
64+ bar
65+ HTML
66+ RUBY
67+ end
68+
69+ it 'registers an offense for dynamic multiline heredoc receiver' do
70+ expect_offense ( <<~'RUBY' )
71+ <<~HTML.html_safe
72+ ^^^^^^^^^ Tagging a string as html safe may be a security risk.
73+ foo
74+ #{bar}
75+ HTML
76+ RUBY
77+ end
78+
4379 it 'registers an offense for variable receiver' do
4480 expect_offense ( <<~RUBY )
4581 foo.html_safe
You can’t perform that action at this time.
0 commit comments