|
130 | 130 | ^^^ Tagging a string as html safe may be a security risk.
|
131 | 131 | RUBY
|
132 | 132 | end
|
| 133 | + |
| 134 | + it 'does not register an offense when using `html_safe` for `I18n.t` method' do |
| 135 | + expect_no_offenses(<<~RUBY) |
| 136 | + I18n.t('foo.bar.baz', scope: [:x, :y, :z]).html_safe |
| 137 | + ::I18n.t('foo.bar.baz', scope: [:x, :y, :z]).html_safe |
| 138 | + RUBY |
| 139 | + end |
| 140 | + |
| 141 | + it 'does not register an offense when using `html_safe` for `I18n.translate` method' do |
| 142 | + expect_no_offenses(<<~RUBY) |
| 143 | + I18n.translate('foo.bar.baz', scope: [:x, :y, :z]).html_safe |
| 144 | + ::I18n.translate('foo.bar.baz', scope: [:x, :y, :z]).html_safe |
| 145 | + RUBY |
| 146 | + end |
| 147 | + |
| 148 | + it 'does not register an offense when using `html_safe` for `t` method' do |
| 149 | + expect_no_offenses(<<~RUBY) |
| 150 | + t('foo.bar.baz').html_safe |
| 151 | + RUBY |
| 152 | + end |
| 153 | + |
| 154 | + it 'does not register an offense when using `html_safe` for `translate` method' do |
| 155 | + expect_no_offenses(<<~RUBY) |
| 156 | + translate('foo.bar.baz').html_safe |
| 157 | + RUBY |
| 158 | + end |
| 159 | + |
| 160 | + it 'does not register an offense when using `html_safe` for `I18n.l` method' do |
| 161 | + expect_no_offenses(<<~RUBY) |
| 162 | + I18n.l(Time.now, locale: :de).html_safe |
| 163 | + ::I18n.l(Time.now, locale: :de).html_safe |
| 164 | + RUBY |
| 165 | + end |
| 166 | + |
| 167 | + it 'does not register an offense when using `html_safe` for `I18n.localize` method' do |
| 168 | + expect_no_offenses(<<~RUBY) |
| 169 | + I18n.localize(Time.now, locale: :de).html_safe |
| 170 | + ::I18n.localize(Time.now, locale: :de).html_safe |
| 171 | + RUBY |
| 172 | + end |
| 173 | + |
| 174 | + it 'does not register an offense when using `html_safe` for `l` method' do |
| 175 | + expect_no_offenses(<<~RUBY) |
| 176 | + l(Time.now).html_safe |
| 177 | + RUBY |
| 178 | + end |
| 179 | + |
| 180 | + it 'does not register an offense when using `html_safe` for `localize` method' do |
| 181 | + expect_no_offenses(<<~RUBY) |
| 182 | + localize(Time.now).html_safe |
| 183 | + RUBY |
| 184 | + end |
133 | 185 | end
|
134 | 186 | end
|
0 commit comments