MyBB Community Forums

Full Version: [F] Bugs in parser
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is from a previous thread:
http://community.mybboard.net/showthread.php?tid=17588

Tikitiki asked me to post here, so:
Quote:
Tikitiki Wrote:As for {{mybb-code}} I ask you to not use it, as there is no other alternative.
Nah, I don't mind that, but I'm suggesting the { and } characters, entered by the user gets replaced with the &xxxx; equivalents. This is what I use in the parser:
		// If MyCode needs to be replaced, first filter out [code] and [php] tags.
		if($options['allow_mycode'] != "no")
		{
			//replace \, { and }s to save trouble later
			$message = str_replace("{", '{', $message);
			$message = str_replace("}", '}', $message);
			$message = str_replace("\\", '\', $message);
			$message = str_replace("\"", '"', $message);

			// First we split up the contents of code and php tags to ensure they're not parsed.
			preg_match_all("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", $message, $code_matches, PREG_SET_ORDER);
			$message = preg_replace("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", "{{mybb-code}}\n", $message);
		}
Oh, and replacing the \ character at that point fixes another bug with the parser.
*EDIT* Note that the '\' is really '\' - this is also a bug :|
Wouldn't replacing { and } mess up the PHP parser? Since it depends on valid code to highlight it wouldn't recognize &#x7B/D as a valid { / } character.
We could change it to { before the PHP code parser is initialized then we could change it back within the php code tag function - since it only matches the text within the PHP code tag.
But might be overkill though.
I agree, I'd just say don't use it please Toungue
ZiNga BuRgA Wrote:This is from a previous thread:
http://community.mybboard.net/showthread.php?tid=17588

Tikitiki asked me to post here, so:
Quote:
Tikitiki Wrote:As for {{mybb-code}} I ask you to not use it, as there is no other alternative.
Nah, I don't mind that, but I'm suggesting the { and } characters, entered by the user gets replaced with the &xxxx; equivalents. This is what I use in the parser:
		// If MyCode needs to be replaced, first filter out [code] and [php] tags.
		if($options['allow_mycode'] != "no")
		{
			//replace \, { and }s to save trouble later
			$message = str_replace("{", '{', $message);
			$message = str_replace("}", '}', $message);
			$message = str_replace("\\", '\', $message);
			$message = str_replace("\"", '"', $message);

			// First we split up the contents of code and php tags to ensure they're not parsed.
			preg_match_all("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", $message, $code_matches, PREG_SET_ORDER);
			$message = preg_replace("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", "{{mybb-code}}\n", $message);
		}
Oh, and replacing the \ character at that point fixes another bug with the parser.
*EDIT* Note that the '\' is really '\' - this is also a bug :|

but but \ already gets converted to \. . .
And also the bug with \ should be \ seems to only exist after editing?
Also other parts of your code will break the whole idea with an highlighter. We can't convert " to &quote; before after the php highlight function has been ran.
I've made a change to this.

The tags are now converted to <mybb-code>. Why? You cannot use HTML in posts and by that time any input of HTML has been converted to &gt; and &lt;.

It's a bit of a "hack" but it solves this problem short of converting different characters such as { and } to entity equivalents which will break the [php] tag parser.
This bug has been fixed in the latest code.

Please note the latest code is not live on the site or for download. An update will be released which contains this fix.