Extra line breaks are created when the line break converter is turned on for an input format (such as Filtered HTML) and the content contains tags that are upper case. For example: <P>foo</P> turns into something like: <p></p><P>foo</p>

Uppercase <TABLE><TR><TD>...</TD></TR></TABLE> tags are even worse.

The function _filter_autop needs to be more case insensitive. There are a lot of preg_replace() calls, but only a couple of them are case insensitive. I would think that any that are looking for a tag name of any kind should be case-insensitive. For example, this line:
$chunk = preg_replace('!<p>\s*(</?'. $block .'[^>]*>)!', "$1", $chunk);
should be (added the i):
$chunk = preg_replace('!<p>\s*(</?'. $block .'[^>]*>)!i', "$1", $chunk);

Comments

vm’s picture

Version: 6.12 » 6.x-dev

I believe this is by design:

the World Wide Web Consortium (W3C) recommends lowercase in HTML 4, and demands lowercase tags in future versions of (X)HTML.

see: http://www.w3schools.com/Html/html_elements.asp

ampersat’s picture

I understand why this might be by design (and I personally prefer lowercase tags whenever possible), but there's a problem with that. Drupal's basic philosophy for user data allows almost anything to be entered into the web interface and subsequently stored in the database (including upper case tags). Formatting, filters, etc. are applied at display time.

This means that output filters need to be able to handle user data...even data that is not standards-compliant.

Otherwise, there needs to be a way to force standards compliance at input, which I'm not sure there is currently.

damien tournoud’s picture

Status: Active » Closed (works as designed)

@bounsy: ensuring HTML compliance is the job of the HTML corrector, that you should run as early as possible in your filter chain. I'm not sure that the Drupal 6 version of the HTML corrector does that well, but the Drupal 7 proposed version (#374441: Refactor Drupal HTML corrector (PHP5)) surely does.

ampersat’s picture

That's useful to know. It does make me wonder, though: Why does the default configuration have the following weights?

URL filter: 0
HTML filter: 1
Line break converter: 2
HTML corrector: 10

If HTML correction is so important to run early, why is it so heavily weighted to run at the end by default? Shouldn't the default have the HTML corrector before the Line break converter at least?

By the way, I just moved Line break converter to the end and everything works great now. Hopefully the Line break converter doesn't produce anything that needs to be corrected, since it is no longer being corrected by the HTML corrector.

imrook’s picture

Status: Closed (works as designed) » Needs review
StatusFileSize
new322 bytes

I found this post after running into the same issue myself. Thanks Damien and bounsy for the suggestion to use the HTML corrector filter and lower the weight. This fixed simple cases for me, but I found there is a bug in the HTML corrector filter: Opening tags are not lowercased. It's actually apparent in the example in the opening post. Here's HTML straight from the node_revisions table that was generated in TinyMCE on IE7:

<P>Testing TinyMCE in IE7</P>
<P>This is a test of multiple lines.</P>
<TABLE border=0>
<TBODY>
<TR>
<TD>
<P>Testing tables in IE7<BR>This is a two line cell</P></TD>
<TD>This is a one line cell</TD></TR>
<TR>
<TD>One line again</TD>
<TD>One line</TD></TR></TBODY></TABLE>

The HTML that gets rendered is the following:

<p><P>Testing TinyMCE in IE7</p>
<p><P>This is a test of multiple lines.</p>
<p><TABLE border=0><br />
<TBODY><br />
<TR><br />
<TD><br />
<P>Testing tables in IE7<BR />This is a two line cell</p>

</td>
<p><TD>This is a one line cell</td>
</tr>
<p><TR><br />
<TD>One line again</td>
<p><TD>One line</td>
</tr>
</tbody>
</table>

Upon inspecting the code for the HTML corrector filter, I found that it only performs strtolower() on the closing tag. The attached patch also calls strtolower() on the opening tag. With the patch applied, I get the following HTML output:

<p>Testing TinyMCE in IE7</p>
<p>This is a test of multiple lines.</p>
<table border=0>
<tbody>
<tr>
<td>
<p>Testing tables in IE7<br />This is a two line cell</p>

</td>
<td>This is a one line cell</td>
</tr>
<tr>
<td>One line again</td>
<td>One line</td>
</tr>
</tbody>
</table>

Comments on this patch are welcome.

c960657’s picture

Version: 6.x-dev » 7.x-dev
StatusFileSize
new3.74 KB

This may be a configuration issue, but in that case I think the default filter configuration is problematic.

To reproduce this:
1. Install HEAD
2. On admin/config/content/formats/2, add these to the list of allowed tags: <p> <br> <table> <th> <td> <tbody>
3. On node/add/article, insert the HTML code from the first code block in comment #7. Then save the node.

The output will look something like the second code block in #7.

You could argue, that the HTML corrector should be run first. I'm not sure about the consequences of this. A less invasive solution is to make the Line break converter filter case insensitive when looking for tags, like e.g. the URL filter is.

This patch basically adds an i modifier to all the regex patterns in _filter_autop(). As a clean-up, it also changes the patterns to use the same delimiter character, ` instead of a number of different characters, and changes a few strings to use single quotes.

The patch has been hand-edited in order to make it easier to review.

damien tournoud’s picture

Status: Needs review » Needs work

Agreed on #8. Could we slightly extend the existing autop tests?

c960657’s picture

Status: Needs work » Needs review
StatusFileSize
new5.51 KB

Added a few tests. Also made the patterns accept <br> and <br/> (both case-insensitive) in addition to <br />.

c960657’s picture

StatusFileSize
new6.33 KB

Reroll.

c960657’s picture

Version: 7.x-dev » 8.x-dev
StatusFileSize
new4.18 KB

Reroll that applies to both 7.x and 8.x.

c960657’s picture

StatusFileSize
new4.22 KB
kscheirer’s picture

#13: filter-autop-5.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, filter-autop-5.patch, failed testing.

c960657’s picture

Status: Needs work » Needs review
StatusFileSize
new4.45 KB

Status: Needs review » Needs work

The last submitted patch, 16: filter-autop-6.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Issue summary: View changes
Status: Needs work » Closed (cannot reproduce)
Issue tags: +Bug Smash Initiative
StatusFileSize
new34.59 KB
new33.11 KB

This seems to be working fine now, have copied the markup from #7 with a bunch of different settings checked for the text format but it always works.

Before:

After: