diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index 402f13aec5..058a2947f1 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,6 +1,11 @@
## Rails 7.0.0.alpha2 (September 15, 2021) ##
-* No changes.
+* Support svg unpaired tags for `tag` helper.
+
+ tag.svg { tag.use('href' => "#cool-icon") }
+ # =>
+
+ *Oleksii Vasyliev*
## Rails 7.0.0.alpha1 (September 15, 2021) ##
diff --git a/actionview/lib/action_view/helpers/tag_helper.rb b/actionview/lib/action_view/helpers/tag_helper.rb
index 20cc79ef3f..665fd5426b 100644
--- a/actionview/lib/action_view/helpers/tag_helper.rb
+++ b/actionview/lib/action_view/helpers/tag_helper.rb
@@ -45,7 +45,8 @@ module ActionView
include CaptureHelper
include OutputSafetyHelper
- VOID_ELEMENTS = %i(area base br col embed hr img input keygen link meta param source track wbr).to_set
+ HTML_VOID_ELEMENTS = %i(area base br col circle embed hr img input keygen link meta param source track wbr).to_set
+ SVG_VOID_ELEMENTS = %i(animate animateMotion animateTransform circle ellipse line path polygon polyline rect set stop use view).to_set
def initialize(view_context)
@view_context = view_context
@@ -66,7 +67,7 @@ module ActionView
def tag_string(name, content = nil, escape_attributes: true, **options, &block)
content = @view_context.capture(self, &block) if block_given?
- if VOID_ELEMENTS.include?(name) && content.nil?
+ if (HTML_VOID_ELEMENTS.include?(name) || SVG_VOID_ELEMENTS.include?(name)) && content.nil?
"<#{name.to_s.dasherize}#{tag_options(options, escape_attributes)}>".html_safe
else
content_tag_string(name.to_s.dasherize, content || "", options, escape_attributes)
diff --git a/actionview/test/template/tag_helper_test.rb b/actionview/test/template/tag_helper_test.rb
index 5c476e37c8..070d252c34 100644
--- a/actionview/test/template/tag_helper_test.rb
+++ b/actionview/test/template/tag_helper_test.rb
@@ -21,6 +21,7 @@ class TagHelperTest < ActionView::TestCase
def test_tag_builder_void_tag
assert_equal "
", tag.br
assert_equal "
", tag.br(class: "some_class")
+ assert_equal "", tag.svg { tag.use("href" => "#cool-icon") }
end
def test_tag_builder_void_tag_with_forced_content