This is when used with a format filter that implements 'Line break converter"
_filter_autop('') == "br" tag.
the doc for the function says :
"Convert line breaks into [p] and [br] in an intelligent fashion.
* Based on: http://photomatt.net/scripts/autop"

The above link reads
"Basically it takes PHP’s nl2br function to the logical next step and converts double line breaks to paragraphs where applicable, does line breaks as before, and best of all it’s aware of block-level HTML tags so it won’t mess up your page"
Yet we have nl2br('') == ''.

So I'm not sure 1) if it's a bug or a feature 2) where it should be corrected if necessary.

I noticed this on an extraneous br tag being output when a rendering a node with no body.

CommentFileSizeAuthor
#12 filter_14.patch1.21 KBRobRoy
#5 filter.module_26.patch1.19 KByched
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

Title: check_plain('') = "br" tag with "Line break converter" filter » check_plain(empty string) = <br>
webchick’s picture

I've noticed this too, and would consider it a bug. At one point I'd filed an issue about this but I can't seem to find it now, and in any case this is a better description than mine. ;) I believe I'd traced it to the filter_xss stuff, which got into Scary Regex Hell (tm) which was beyond my level of debugging skills.

Steven’s picture

Title: check_plain(empty string) = <br> » check_markup(empty string) = <br>

Correcting title. Check_plain() will never add HTML to the output.

yched’s picture

Er, right, stupid mistake - sorry.

yched’s picture

Status: Active » Needs review
FileSize
1.19 KB

I think I nailed this to the following lines in _filter_autop :

$chunk = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $chunk); // make paragraphs, including one at the end
$chunk = preg_replace('|<p>\s*?</p>|', '', $chunk); // under certain strange conditions it could create a P of entirely whitespace

1st line creates some <p>...</p>\n blocks.
2nd line corrects some seemingly "strange" effects in this first line where empty <p></p> are created and removes them _but_ forgets the trailing \n in the capturing pattern.

Attached patch corrects this.

Side note : this should also correct the behaviour where a <br/> gets inserted between two <pre> blocks following each other
Demo right below :
<code>aabb
outputs : (also note the <br/> that gets added after the second <pre>)
aabb

anders.fajerson’s picture

Status: Needs review » Needs work

I still get a br tag, both on a custom module which allows empty bodies and when erasing the body for a page content type in the db.

yched’s picture

Status: Needs work » Needs review

fajerstarter : I don't see that myself (with that patch).
Can you provide additional info on your filters configuration ?
What are the filters (and their settings) your content goes through ?

This patch deals with a bug in the "Line break converter" filter, and AFAICS, solves it. Maybe you're experiencing a related but different bug ?

anders.fajerson’s picture

I had no idea that the input format was "cached". When re-saving the input formats (standard; Filtered and full HTML) it works as advertised, took a while until I figured that out.. Can that extra step be dealt with in the patch?

yched’s picture

Yes, it's only after replying to you and leaving home that I thought about cached filter results - sorry about that.

So, to anyone willing to test the patch : you'll have to empty your cache after applying.

PS : no, the patch itself can't deal with this - maybe it this gets in an update function could ba added to empty the cache (but I doubt it :-) or else system.install would be overcrowded by simple 'empty cache' updates).

Steven’s picture

Status: Needs review » Fixed

Good catch. Tested and verified. Committed to HEAD, thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)
RobRoy’s picture

Version: 5.x-dev » 4.7.x-dev
Status: Closed (fixed) » Reviewed & tested by the community
FileSize
1.21 KB

killes, How about a backport? I'm running across this on 4.7.

Marked http://drupal.org/node/71927 as a dupe.

killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)