MyBB Community Forums

Full Version: [F] bbcodes parse invalid HTML in some cases
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
if you tried to validate this post
you will see this error
Line 246, Column 48: document type does not allow element "div" here; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag.

					<u><strong><div style="text-align: center;">test this</div></strong></u>

it's becuase of parsing a div tag inside <strong> tag..
so I would like to make the following changes to inc/class_parser.php
find
$standard_mycode['b']['regex'] = "#\[b\](.*?)\[/b\]#si";
		$standard_mycode['b']['replacement'] = "<strong>$1</strong>";

		$standard_mycode['u']['regex'] = "#\[u\](.*?)\[/u\]#si";
		$standard_mycode['u']['replacement'] = "<u>$1</u>";

		$standard_mycode['i']['regex'] = "#\[i\](.*?)\[/i\]#si";
		$standard_mycode['i']['replacement'] = "<em>$1</em>";
replace with
		$standard_mycode['b']['regex'] = "#\[b\](.*?)\[/b\]#si";
		$standard_mycode['b']['replacement'] = "<div style=\"font-weight:bold;display: inline;\">$1</div>";

		$standard_mycode['u']['regex'] = "#\[u\](.*?)\[/u\]#si";
		$standard_mycode['u']['replacement'] = "<div style=\"text-decoration:underline;display: inline;\">$1</div>";

		$standard_mycode['i']['regex'] = "#\[i\](.*?)\[/i\]#si";
		$standard_mycode['i']['replacement'] = "<div style=\"font-style:italic;display: inline;\">$1</div>";

find
$standard_mycode['color']['regex'] = "#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#si";
		$standard_mycode['color']['replacement'] = "<span style=\"color: $1;\">$2</span>";

		$standard_mycode['size']['regex'] = "#\[size=(xx-small|x-small|small|medium|large|x-large|xx-large)\](.*?)\[/size\]#si";
		$standard_mycode['size']['replacement'] = "<span style=\"font-size: $1;\">$2</span>";

		$standard_mycode['size_int']['regex'] = "#\[size=([0-9\+\-]+?)\](.*?)\[/size\]#esi";
		$standard_mycode['size_int']['replacement'] = "\$this->mycode_handle_size(\"$1\", \"$2\")";

		$standard_mycode['font']['regex'] = "#\[font=([a-z ]+?)\](.+?)\[/font\]#si";
		$standard_mycode['font']['replacement'] = "<span style=\"font-family: $1;\">$2</span>";

		$standard_mycode['align']['regex'] = "#\[align=(left|center|right|justify)\](.*?)\[/align\]#si";
		$standard_mycode['align']['replacement'] = "<div style=\"text-align: $1;\">$2</div>";
replace with
$standard_mycode['size']['regex'] = "#\[size=(xx-small|x-small|small|medium|large|x-large|xx-large)\](.*?)\[/size\]#si";
		$standard_mycode['size']['replacement'] = "<div style=\"font-size: $1;display: inline;\">$2</div>";

		$standard_mycode['size_int']['regex'] = "#\[size=([0-9\+\-]+?)\](.*?)\[/size\]#esi";
		$standard_mycode['size_int']['replacement'] = "\$this->mycode_handle_size(\"$1\", \"$2\")";

		$standard_mycode['font']['regex'] = "#\[font=([a-z ]+?)\](.+?)\[/font\]#si";
		$standard_mycode['font']['replacement'] = "<div style=\"font-family: $1;display: inline;\">$2</div>";

		$standard_mycode['align']['regex'] = "#\[align=(left|center|right|justify)\](.*?)\[/align\]#si";
		$standard_mycode['align']['replacement'] = "<div style=\"text-align: $1; \">$2</div>";

find
	function mycode_handle_size($size, $text)
	{
		$size = intval($size)+10;

		if($size > 50)
		{
			$size = 50;
		}

		$text = "<span style=\"font-size: {$size}pt\">".str_replace("\'", "'", $text)."</span>";

		return $text;
	}
replace with
	function mycode_handle_size($size, $text)
	{
		$size = intval($size)+10;

		if($size > 50)
		{
			$size = 50;
		}

		$text = "<div style=\"font-size: {$size}pt; display: inline;\">".str_replace("\'", "'", $text)."</div>";

		return $text;
	}

for me I test it, and it's fix any invalid html parsing..
what you think?
And does it work without breaking anything in any browsers? (i.e. 6/7, ff 2/3, safari, opera?)
I tested it with FF3,IE6, IE7, opera 9.50 build 10063 and netscape navigator 9.0.0.6
and no line breaks, thats why I used display: inline; thats make the div treat like span
Does the font tag need display: inline;? I didn't see that added
yes all of it need to not to break line whene it's used, expect the alignment tag..
I added it to the code
Thank you for your bug report.

This bug has been fixed in our internal code repository. Please note that the problem will not be fixed here until these forums are updated.
thanks mate
I might add that the <div> tags break posts like these... :/
http://community.mybboard.net/thread-336...#pid226678

(at least on FF3, FF3 appears to be sticking a </p> before the <div> )
it's didn't seem to be breaked here (FF 3)
(2008-07-16, 11:09 AM)ZiNgA BuRgA Wrote: [ -> ]I might add that the <div> tags break posts like these... :/
http://community.mybboard.net/thread-336...#pid226678

(at least on FF3, FF3 appears to be sticking a </p> before the <div> )

It doesn't break it here either. FF3.
Pages: 1 2