Problem/Motivation

The HTML specification recommends not to output trailing slashes for void elements. For example, when I run the W3C validator on https://dri.es/, I get the following output:

A screenshot of the W3C HMTL validator showing a notice about trailing slashes on void elements.

For more information, see https://github.com/validator/validator/wiki/Markup-%C2%BB-Void-elements.

Proposed resolution

Change line 88 in of ./lib/Drupal/Core/Render/Element/HtmlTag.php. The function preRenderHtmlTag() is responsible for adding the trailing slash.

Issue fork drupal-3346188

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Dries created an issue. See original summary.

dries’s picture

Issue summary: View changes

whitedevil made their first commit to this issue’s fork.

tinto’s picture

Version: 11.0.x-dev » 10.1.x-dev
tinto’s picture

StatusFileSize
new589 bytes

This patch simply changes the closing of the opening tag for void elements from /> to > on line 91 of core/lib/Drupal/Core/Render/Element/HtmlTag.php.

tinto’s picture

StatusFileSize
new19.1 KB
new17.64 KB

Some code refactoring in core/lib/Drupal/Core/Render/Element/HtmlTag.php and fixing automated test fails.

tinto’s picture

Status: Active » Needs review
smustgrave’s picture

The idea makes sense but my concern with making such a change could cause issues for existing sites. Maybe both scenarios should be supported with a warning for the old way?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Going to see what the committers think.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: 3346188-6-10.1.x.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Seems random

catch’s picture

I think this is probably OK, it would likely only fail if a site specifies xhtml output which I doubt any are doing these days. However putting in front of the front end framework managers for a look.

poker10’s picture

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: 3346188-6-10.1.x.patch, failed testing. View results

tinto’s picture

Status: Needs work » Closed (duplicate)
Issue tags: +ddd2023

I was about to reroll #6, but after discussing briefly with @laurii and @longwave, I've decided to mark this issue as duplicate of #1388926: Remove all references to "self-closing" void elements in core. The work done in that issue probably covers all void elements everywhere, including the code covered here.

Let's continue the work there!

webtematica’s picture

This happen in Drupal 10 also.
EDIT: Sorry i just see it refers to drupal 10

juanjol’s picture

StatusFileSize
new19.1 KB

Uploaded patch in #6 with 10.2 compatibility for projects that rely on this patch, until related Issue is fixed, or a valid solution is found.

juanjol’s picture

StatusFileSize
new19.1 KB

Wrong patch filename, fixing it.

tinto’s picture

Thanks for the patch, Juanjol. However, this issue was marked Closed (duplicate).

I suggest we continue to discuss/work in #1388926: Remove all references to "self-closing" void elements in core, starting with the discussion about how we can improve the issue by dividing the work needed into seperate issues with a smaller scope.

bryan toapanta’s picture

StatusFileSize
new19.09 KB

Uploaded patch in #19 with 10.2.4 compatibility.