Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove trailing slash from void HTML elements #51646

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion actionpack/test/controller/renderer_test.rb
Expand Up @@ -117,7 +117,7 @@ class RendererTest < ActiveSupport::TestCase
end

test "rendering with helpers" do
assert_equal "<p>1\n<br />2</p>", render(inline: '<%= simple_format "1\n2" %>')
assert_equal "<p>1\n<br>2</p>", render(inline: '<%= simple_format "1\n2" %>')
end

test "rendering with user specified defaults" do
Expand Down
22 changes: 22 additions & 0 deletions actionview/CHANGELOG.md
Expand Up @@ -94,4 +94,26 @@

*Akhil G Krishnan*

* Removed the trailing slash from void HTML elements, except for elements included inside SVG tags.
ahukkanen marked this conversation as resolved.
Show resolved Hide resolved

The default value of the third argument (`open`) for `ActionView::TagHelper#tag` has been changed from `false` to `nil`.

For example, the following code now creates HTML without the trailing slash on the void element:

```ruby
# Prints out `<br>`
tag("br")
```

To force the trailing slash on the element, the third argument (`open`) can be provided with the value `false` as in:

```ruby
# Prints out `<br />`
tag("br", nil, false)
```

In order to preserve the legacy XHTML format, set `Rails.application.config.action_view.void_element_trailing_slash` to `true`.

*Antti Hukkanen*

Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/actionview/CHANGELOG.md) for previous changes.
6 changes: 3 additions & 3 deletions actionview/app/assets/javascripts/rails-ujs.esm.js
ahukkanen marked this conversation as resolved.
Show resolved Hide resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions actionview/app/assets/javascripts/rails-ujs.js
ahukkanen marked this conversation as resolved.
Show resolved Hide resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion actionview/lib/action_view/base.rb
Expand Up @@ -24,7 +24,7 @@ module ActionView # :nodoc:
#
# <b>Names of all the people</b>
# <% @people.each do |person| %>
# Name: <%= person.name %><br/>
# Name: <%= person.name %><br>
# <% end %>
#
# The loop is set up in regular embedding tags <tt><% %></tt>, and the name is written using the output embedding tag <tt><%= %></tt>. Note that this
Expand Down
100 changes: 50 additions & 50 deletions actionview/lib/action_view/helpers/asset_tag_helper.rb

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions actionview/lib/action_view/helpers/asset_url_helper.rb
Expand Up @@ -30,9 +30,9 @@ module Helpers # :nodoc:
# Helpers take that into account:
#
# image_tag("rails.png")
# # => <img src="http://assets.example.com/assets/rails.png" />
# # => <img src="http://assets.example.com/assets/rails.png">
# stylesheet_link_tag("application")
# # => <link href="http://assets.example.com/assets/application.css" rel="stylesheet" />
# # => <link href="http://assets.example.com/assets/application.css" rel="stylesheet">
#
# Browsers open a limited number of simultaneous connections to a single
# host. The exact number varies by browser and version. This limit may cause
Expand All @@ -43,9 +43,9 @@ module Helpers # :nodoc:
# "assets0.example.com", ..., "assets3.example.com".
#
# image_tag("rails.png")
# # => <img src="http://assets0.example.com/assets/rails.png" />
# # => <img src="http://assets0.example.com/assets/rails.png">
# stylesheet_link_tag("application")
# # => <link href="http://assets2.example.com/assets/application.css" rel="stylesheet" />
# # => <link href="http://assets2.example.com/assets/application.css" rel="stylesheet">
#
# This may improve the asset loading performance of your application.
# It is also possible the combination of additional connection overhead
Expand All @@ -69,9 +69,9 @@ module Helpers # :nodoc:
# "http://assets#{OpenSSL::Digest::SHA256.hexdigest(source).to_i(16) % 2 + 1}.example.com"
# }
# image_tag("rails.png")
# # => <img src="http://assets1.example.com/assets/rails.png" />
# # => <img src="http://assets1.example.com/assets/rails.png">
# stylesheet_link_tag("application")
# # => <link href="http://assets2.example.com/assets/application.css" rel="stylesheet" />
# # => <link href="http://assets2.example.com/assets/application.css" rel="stylesheet">
#
# The example above generates "http://assets1.example.com" and
# "http://assets2.example.com". This option is useful for example if
Expand All @@ -88,9 +88,9 @@ module Helpers # :nodoc:
# end
# }
# image_tag("rails.png")
# # => <img src="http://assets.example.com/assets/rails.png" />
# # => <img src="http://assets.example.com/assets/rails.png">
# stylesheet_link_tag("application")
# # => <link href="http://stylesheets.example.com/assets/application.css" rel="stylesheet" />
# # => <link href="http://stylesheets.example.com/assets/application.css" rel="stylesheet">
#
# Alternatively you may ask for a second parameter +request+. That one is
# particularly useful for serving assets from an SSL-protected page. The
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/helpers/date_helper.rb
Expand Up @@ -1161,7 +1161,7 @@ def prompt_option_tag(type, options)
# Builds hidden input tag for date part and value.
#
# build_hidden(:year, 2008)
# => "<input type="hidden" id="date_year" name="date[year]" value="2008" autocomplete="off" />"
# => "<input type="hidden" id="date_year" name="date[year]" value="2008" autocomplete="off">"
def build_hidden(type, value)
select_options = {
type: "hidden",
Expand Down