From f037e1d6baa069b324b7a0fd6eaffbdfb5c6f4dc Mon Sep 17 00:00:00 2001
From: Starla Insigna <hatkirby@fourisland.com>
Date: Sat, 13 Dec 2008 10:18:55 -0500
Subject: Fixed BBCode parsing glitch

As previously seen in the 24 Ways post, there was a strange BBCode parsing glitch caused by a few circumstances. There had to be a BBCode tag that
had a parametered definition and a non-parametered definition. Both had to appear in the same post and the parametered had to appear before the
non-parametered.

Because the Four Island BBCode parsing system parses non-parametered tags first, it finds the opening tag of the non-parametered tag first, but when
it tries to find the closing tag, because it is searching from the beginning of the tag, it finds the closing tag of the parametered tag. This causes
strange things to happen.

This has been fixed by forcing the parsing system to start searching for the closing tag after the position where the starting tag is.
---
 includes/bbcode.php | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

(limited to 'includes/bbcode.php')

diff --git a/includes/bbcode.php b/includes/bbcode.php
index e4b3d7f..40533a3 100755
--- a/includes/bbcode.php
+++ b/includes/bbcode.php
@@ -68,8 +68,9 @@ class BBCode
 			while (strpos($to_parse, '[' . $name . ']') !== FALSE)
 			{
 				$bbcode_uid = unique_id();
-				$to_parse = substr_replace($to_parse, '[' . $name . ':' . $bbcode_uid . ']', strpos($to_parse, '[' . $name . ']'), strlen($name) + 2);
-				$to_parse = substr_replace($to_parse, '[/' . $name . ':' . $bbcode_uid . ']', strpos($to_parse, '[/' . $name . ']'), strlen($name) + 3);
+				$bbpos = strpos($to_parse, '[' . $name . ']');
+				$to_parse = substr_replace($to_parse, '[' . $name . ':' . $bbcode_uid . ']', $bbpos, strlen($name) + 2);
+				$to_parse = substr_replace($to_parse, '[/' . $name . ':' . $bbcode_uid . ']', strpos(substr($to_parse, $bbpos), '[/' . $name . ']') + $bbpos, strlen($name) + 3);
 
 				$value = str_replace('{CONTENT}', '\1', $value);
 				$to_parse = preg_replace('/\[' . $name . ':' . $bbcode_uid . '\](.*)\[\/' . $name . ':' . $bbcode_uid . '\]/', $value, $to_parse);
@@ -81,8 +82,9 @@ class BBCode
 			while (strpos($to_parse, '[' . $name . '=') !== FALSE)
 			{
 				$bbcode_uid = unique_id();
-				$to_parse = substr_replace($to_parse, '[' . $name . ':' . $bbcode_uid . '=', strpos($to_parse, '[' . $name . '='), strlen($name) + 2);
-				$to_parse = substr_replace($to_parse, '[/' . $name . ':' . $bbcode_uid . ']', strpos($to_parse, '[/' . $name . ']'), strlen($name) + 3);
+				$bbpos = strpos($to_parse, '[' . $name . '=');
+				$to_parse = substr_replace($to_parse, '[' . $name . ':' . $bbcode_uid . '=', $bbpos, strlen($name) + 2);
+				$to_parse = substr_replace($to_parse, '[/' . $name . ':' . $bbcode_uid . ']', strpos(substr($to_parse, $bbpos), '[/' . $name . ']') + $bbpos, strlen($name) + 3);
 
 				$value = str_replace('{PARAM}', '\1', $value);
 				$value = str_replace('{CONTENT}', '\2', $value);
-- 
cgit 1.4.1