Skip to content

Commit aca32f3

Browse files
authored
Fix html escaping non strings (#1961)
1 parent cc7c313 commit aca32f3

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

docs/CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ nav_order: 5
1010

1111
## main
1212

13+
* Fix html escaping in `#call` for non-strings.
14+
15+
*Reegan Viljoen, Cameron Dutro*
16+
1317
* Add `output_preamble` to match `output_postamble`, using the same safety checks.
1418

15-
*Kali Donovan*
16-
*Michael Daross*
19+
*Kali Donovan, Michael Daross*
1720

1821
* Exclude html escaping of I18n reserved keys with `I18n::RESERVED_KEYS` rather than `I18n.reserved_keys_pattern`.
1922

lib/view_component/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def content_evaluated?
318318

319319
def maybe_escape_html(text)
320320
return text if request && !request.format.html?
321-
return text if text.nil? || text.empty?
321+
return text if text.blank?
322322

323323
if text.html_safe?
324324
text
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class InlineIntegerComponent < ViewComponent::Base
2+
def call
3+
1
4+
end
5+
end

test/sandbox/test/slotable_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,4 +752,10 @@ def test_slot_names_can_start_with_call
752752
end
753753
end
754754
end
755+
756+
def test_inline_html_escape_with_integer
757+
assert_nothing_raised do
758+
render_inline InlineIntegerComponent.new
759+
end
760+
end
755761
end

0 commit comments

Comments
 (0)