'Convert line breaks into HTML' prepends any <input> with <br>

Created on 28 April 2025, 16 days ago

Problem/Motivation

Enabling the Convert line breaks into HTML filter for a text format in Drupal 11 results in <br> added before any <input> tag, even if the source has no line breaks or spaces. Perhaps notably, Drupal 6 does not seem to be affected.

Steps to reproduce

  1. When editing a node, select a text format that has the Convert line breaks into HTML option enabled (/admin/config/content/formats).
  2. Click on Source if CKEditor is enabled.
  3. Enter Test<input> and ensure there are no empty lines.
  4. Preview or Save the node.

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.1 🔥

Component

text.module

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @rozzi
  • 🇳🇿New Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies . Also mentioned on the version section of the list of issue fields documentation.

  • 🇮🇳India annmarysruthy

    I was able to reproduce the issue by following these steps:

    1. Enabled the "Convert line breaks into HTML" filter for a text format at /admin/config/content/formats.
    2. Created a node using that text format.
    3. Entered Test in the body using the "Source" view in CKEditor, ensuring no extra whitespace or newlines were present.
    4. Saved the node and viewed the output on the frontend.

    Even though the saved source remains

    Test

    , the rendered output includes a line break (
    ) between "Test" and the tag.

    _filter_autop() function in filter.module is responsible for converting line breaks into
    and wrapping text in

    tags. Within this function, there's a $block regex pattern that defines all block-level elements:
    $block = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|input|p|h[1-6]|fieldset|legend|hr|article|aside|details|figcaption|figure|footer|header|hgroup|menu|nav|section|summary)';
    Since is listed as a block-level element,a newline is added before any tag. Later in the processing, this newline gets transformed into

    Proposed Resolution:
    According to HTML specifications, is an inline-level element, not a block-level one. Therefore, it should not be included in the $block list used by _filter_autop().

    Removing input from the $block list resolves the issue, as the newline is no longer added before the tag, and no
    is inserted.

  • Pipeline finished with Success
    16 days ago
    Total: 1692s
    #484617
Production build 0.71.5 2024