Skip to content

Commit

Permalink
Fix html escaping non strings (#1961)
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron authored Jan 8, 2024
1 parent cc7c313 commit aca32f3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
7 changes: 5 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ nav_order: 5

## main

* Fix html escaping in `#call` for non-strings.

*Reegan Viljoen, Cameron Dutro*

* Add `output_preamble` to match `output_postamble`, using the same safety checks.

*Kali Donovan*
*Michael Daross*
*Kali Donovan, Michael Daross*

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

Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def content_evaluated?

def maybe_escape_html(text)
return text if request && !request.format.html?
return text if text.nil? || text.empty?
return text if text.blank?

if text.html_safe?
text
Expand Down
5 changes: 5 additions & 0 deletions test/sandbox/app/components/inline_integer_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class InlineIntegerComponent < ViewComponent::Base
def call
1
end
end
6 changes: 6 additions & 0 deletions test/sandbox/test/slotable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -752,4 +752,10 @@ def test_slot_names_can_start_with_call
end
end
end

def test_inline_html_escape_with_integer
assert_nothing_raised do
render_inline InlineIntegerComponent.new
end
end
end

0 comments on commit aca32f3

Please sign in to comment.