filter_autop() returns <br /> but should return <br> for HTML5

Created on 3 October 2014, over 9 years ago
Updated 29 April 2024, about 2 months ago

filter_autop currently inserts <br />. As we are moving towards html5 ( 📌 Remove all references to "self-closing" void elements in core Needs work ) and remove all references to <br />. let's return <br> in this filter.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Filter 

Last updated about 19 hours ago

No maintainer
Created by

🇳🇱Netherlands Hanno

Live updates comments and jobs are added and updated live.
  • html5

    Implements and supports the use of HTML5.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom catch
    +++ b/core/modules/filter/tests/src/Kernel/FilterKernelTest.php
    @@ -987,7 +987,7 @@ public function testHtmlCorrectorFilter() {
         $this->assertEquals('<img src="http://example.com/test.jpg" />test', $f, 'HTML corrector -- Automatically close single tags.');
     
    -    $f = Html::normalize('<br></br>');
    +    $f = Html::normalize('<br>');
         $this->assertEquals('<br />', $f, "HTML corrector -- Transform empty tags to a single closed tag if the tag's content model is EMPTY.");
     
    

    Shouldn't this test both until HtmlCorrector also puts out HTML 5 instead of changing from one to the other?

  • Status changed to Closed: outdated 7 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    #28++

  • 🇺🇸United States trackleft2

    Rerolled patch against 11.x

  • Status changed to Needs review 5 months ago
  • 🇬🇧United Kingdom longwave UK
  • Status changed to Needs work 5 months ago
  • The Needs Review Queue Bot tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • First commit to issue fork.
  • Merge request !6262converting to MR for easy review → (Open) created by Hardik_Patel_12
  • Pipeline finished with Success
    5 months ago
    #80584
  • 🇺🇸United States trackleft2

    On sites that are updated from Drupal 10.1 to Drupal 10.2 we see the following

    On a site using Drupal Core 10.1 add a text format with both of these filters in the following order.

    1. "Limit allowed HTML tags and correct faulty HTML"
    2. "Convert line breaks into HTML (i.e.
    and

    )"

    Then add a content type, and a text area field, and allow the text format to be used by your user etc.

    Then edit source and add

    
    <p>first line<br>
    second line</p>
    
    

    Note the line break character after the <br> (a UTF-8 0A character in the database).

    Now update your site to Drupal 10.2 and see two <br> elements where there should be one.
    In the database, this value for a text area will cause the issue of two <br> elements:

    These have no line break character after the
    .

    These values will NOT exhibit the issue:

    <p>first line<br>second line</p>
    <p>first line<br />second line</p>
    

    Note that these do not have a UTF-8 0A line break character after the
    .

    In a text format, moving the "Convert line breaks into HTML (i.e.
    and

    )" filter above the "Limit allowed HTML tags and correct faulty HTML" filter also resolves the issue of two
    elements being output where only one was before.

  • 🇺🇸United States mkindred

    I think I'm running into this issue, but the circumstances are (confusingly) different.

    I'm on 10.2.1, and I'm currently upgrading from ckeditor4 contrib to ckeditor5. I'm not using "Convert line breaks into HTML (i.e. <br> and <p>)" before or after the upgrade, yet I'm seeing doubled linebreaks after the upgrade. If I open the offending node for editing, the linebreaks look normal (single), and saving the node fixes them.

    The only two filters I have enabled (before and after the upgrade) are:

    - Limit allowed HTML tags and correct faulty HTML
    - Correct faulty and chopped off HTML

    If I apply patch #30 with the upgrade, it seems to fix the doubled linebreaks. If I'm not using the "Convert line breaks..." filter, should this patch affect me?

  • 🇬🇧United Kingdom longwave UK

    Fixing title, hiding patches. Added some questions to the MR.

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
  • 🇺🇸United States mkindred

    @longwave I tried and cannot reproduce this behavior on a clean install. My ckeditor upgrade involved ~10 commits, so I'm reviewing each one to see where the issue entered.

  • 🇺🇸United States mkindred

    Well, that's embarrassing. I did indeed have the "convert line breaks" filter enabled. I've been trying to remove old text formats for some time, and I didn't realize one of the older formats was still being used.

    So to update: patch #30 does fix the issue for me while upgrading from ckeditor4 to ckeditor5 on D10.2.1 while using the "Convert line breaks into HTML" filter.

  • 🇩🇪Germany Ammaletu Bonn, Germany

    I can confirm that the Merge Request as it is fixes this issue in Drupal 10.2.5. We just upgraded from CKEditor 4 to 5 and had extra linebreaks whenever the source contained a linebreak right inside the paragraph (not sure how our customers managed to get the linebreaks there).

    This issue turns 10 years old in just a couple of months. As far as I can see, the MR title needs to be changed and one change to the test case needs to be reverted. I tried to do that, but Gitlab wouldn't let me.

Production build 0.69.0 2024