The filter "Convert line breaks into HTML (i.e. <br> and <p>)" generates duplicate br tags after a line ending in a break tag that doesn't exactly match <br />

Created on 26 September 2019, about 5 years ago
Updated 8 August 2024, 3 months ago

Problem/Motivation

The Convert line breaks into HTML (i.e. <br> and <p>) filter adds an additional break tag when a line is ended by a break tag that does not exactly match <br />, any variation such as additional attributes or using a non self closing tag will result in multiple br tags.

Steps to reproduce

  1. Go to /admin/config/content/formats/full_html
  2. Enable the "Convert line breaks into HTML (i.e. <br> and <p>)" filter under the "Enabled filters" section.
  3. Add the following html to the node's body field with text format "Full HTML" and save, an additional break tag will be added to the second line.
<p>First Line<br />
Second Line<br class='second' />
Third line</p>

Proposed resolution

Generalize or replace the preg_replace call in _filter_autop so that it no longer adds an additional break tag to a line that ends in a break tag no matter the existing break tag's structure.

Remaining tasks

Tests need to be written

User interface changes

none

API changes

none

Data model changes

none

Release notes snippet

Generalized the _filter_autop filter to no longer generate duplicate break tags when a break tag already exists.

Original report by Jieyyal

We want to have different behavior for br tag for different device, so we're using < br class='*' / > in our body text area.

Reproduce steps:
1.Go to /admin/config/content/formats/full_html, Enable filter "Convert line breaks into HTML (i.e. < br > and < p >)" under section "Enabled filters"
2.Add below html to node's body field with text format "Full HTML" and save

<p>First Line<br />
Second Line<br class='second' />
Third line</p>

3.View the node page and check view source, will find a duplicated br tag after "< br class='second' >" tag

<p>Hello <br>
Second line<br class="second"><br>
Third line</p>

Expect:
Should render what we input and remove the extra < br > tag

<p>Hello <br>
Second line<br class="second">
Third line</p>

What happened instead?
We're getting an extra < br > tag after < br class='second' >

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
FilterΒ  β†’

Last updated about 5 hours ago

No maintainer
Created by

πŸ‡¨πŸ‡³China Jieyyal

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

Production build 0.71.5 2024