Welcome! » Log In » Create A New Profile

HTML Truncated Due To Unmatched Div Tag

Posted by laurin1 
HTML Truncated Due To Unmatched Div Tag
March 12, 2012 09:55PM

Why does it truncate everything after</div>?


Test1</div>
<table>
	<tr>
		<td>
			Test2
		</td>
	</tr>
</table>

Any other tag unbalanced does not do this, just div. Why is that? How can I make it not do this?

Re: HTML Truncated Due To Unmatched Div Tag
March 13, 2012 12:50AM

Yeah, known bug. A bit annoying. Use %Core.LexerImpl set to DirectLex to avoid it (but take a performance hit and some parsing behavior changes!).

Re: HTML Truncated Due To Unmatched Div Tag
March 13, 2012 11:08AM

Is there a bug reporting tool or a place to vote for bugs or give feedback?

Re: HTML Truncated Due To Unmatched Div Tag
March 13, 2012 12:00PM

We don't have a bug tracker; so forums are usually the best place.

Re: HTML Truncated Due To Unmatched Div Tag
March 13, 2012 12:04PM

Tried to post a reply, but can't:

http://htmlpurifier.org/phorum/read.php?3,6257

Re: HTML Truncated Due To Unmatched Div Tag
March 13, 2012 12:16PM

For now, I've fixed it like this:

	/**
	 * @static
	 * @param string $sHTML
	 * @return string
	 */
	public static function getHTMLWithFixForUnmatchedDivTags($sHTML){

		$iOpeningDivCount  = preg_match_all('/<div/', $sHTML, $aMatches);
		$iClosingDivCount  = preg_match_all('/<\/div>/', $sHTML, $aMatches);
		$sExtraOpeningDivs = null;

		if($iClosingDivCount > $iOpeningDivCount)
			for($i = 1; $i <= ($iClosingDivCount - $iOpeningDivCount); $i++)
				$sExtraOpeningDivs .= "<div>";

		return $sExtraOpeningDivs.$sHTML;

	}
Author:
Your Email:

Subject:

HTML input is enabled. Make sure you escape all HTML and angled brackets with &lt; and &gt;.

Auto-paragraphing is enabled. Double newlines will be converted to paragraphs; for single newlines, use the pre tag.

Allowed tags: a, abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, div, dl, dt, em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var.

For inputting literal code such as HTML and PHP for display, use CDATA tags to auto-escape your angled brackets, and pre to preserve newlines:

<pre><![CDATA[
Place code here
]]></pre>

Power users, you can hide this notice with:

.htmlpurifier-help {display:none;}

Message: