Skip to:
Content

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#795 closed defect (fixed)

posts re-saved with non-ending html tags are improperly handled (has fix)

Reported by: _ck_ Owned by: mdawaffe
Milestone: 0.9 Priority: high
Severity: normal Version: 0.8.3.1
Component: Back-end Keywords: has-patch
Cc:

Description

Some html tags are re-encoded into html entities by bbpress when posts are edited and re-saved.

For example, if you put a <br> or <hr> into a post (with those tags in the allowed list) and then save it, the first time it's stored correctly and displayed corrected - while bbPress formats them to xhtml ie. <br /> or <hr />

But the next time you edit the post and re-save, bbpress will turn the tags into html entities and they no longer function as tags.

ie. &lt; br /&gt; or &lt; hr /&gt;

Change History (6)

comment:1 _ck_6 years ago

  • Milestone set to 0.8.4
  • Priority changed from normal to high
  • Summary changed from posts re-saved with non-ending html tags are improperly handled to posts re-saved with non-ending html tags are improperly handled (has fix)

Apparently the problem lies within bb_encode_bad.
Here is an enhanced tested fix:

function bb_encode_bad( $text ) {
	$text = wp_specialchars( $text );
	$text = preg_replace("|&lt;br\s*?/*?&gt;|", "<br />", $text);
	foreach ( bb_allowed_tags() as $tag => $args ) {
		if ( 'br' == $tag )
			continue;
		if ('hr'==$tag || 'img'==$tag) 
			$text = preg_replace("|&lt;$tag\s*?/*?&gt;|", "<$tag />", $text);					
		elseif ( $args )
			$text = preg_replace("|&lt;(/?$tag.*?)&gt;|", '<$1>', $text);
		else
			$text = preg_replace("|&lt;(/?$tag)&gt;|", '<$1>', $text);
	}
	
	return $text;
}

comment:2 mdawaffe6 years ago

  • Keywords has-patch added
  • Owner set to mdawaffe
  • Severity changed from major to normal
  • Status changed from new to assigned
  • Version set to 0.8.3.1

That converts all image tags to <img /> (stripping the src, alt, etc.).

How does this look to you?

function bb_encode_bad( $text ) {
        $text = wp_specialchars( $text );

        $allowed = bb_allowed_tags();

        $empty = array( 'br' => true, 'hr' => true, 'img' => true, 'input' => true, 'param' => true, 'area' => true, 'col' => true );

        foreach ( $allowed as $tag => $args ) {
                if ( $args )
                        $tag = "$tag.*?";

                if ( isset( $empty[$tag] ) ) {
                        $text = preg_replace("|&lt;($tag)\s*?/*?&gt;|", '<$1 />', $text);
                        continue;
                }

                $text = preg_replace("|&lt;(/?$tag)&gt;|", '<$1>', $text);
        }

        return $text;
}

comment:3 mdawaffe6 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [1156]) fix empty element processing in bb_encode_bad(). Fixes #795 props _ck_

comment:4 mdawaffe6 years ago

(In [1157]) fix empty element processing in bb_encode_bad(). Fixes #795 props _ck_ for branches/0.8

comment:5 mdawaffe6 years ago

(In [1158]) logic bug in bb_encode_bad(). Fixes #795

comment:6 mdawaffe6 years ago

(In [1159]) logic bug in bb_encode_bad(). Fixes #795 for branches/0.8

Note: See TracTickets for help on using tickets.