MyBB Community Forums

Full Version: [wontfix] ] in username breaks quote
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(2009-02-22, 12:43 PM)bobbit Wrote: [ -> ]... or just have them convert to & #91; and & #93;? Everything will read them as that, users will still see them as [], problem solved.
You can't really put that in the code unfortunately. If you inserted "[" into the code, the editor would automatically convert it to "[" - if you tried "[" it would display properly, but by the nature of htmlspecialchars_uni, there's no guarantee it'll remain after editing.
Still an interesting idea though - thanks for putting it forward Smile
Oh well Smile
(2009-02-22, 12:43 PM)bobbit Wrote: [ -> ]... or just have them convert to & #91; and & #93;? Everything will read them as that, users will still see them as [], problem solved.

I had this in mind but I didn't know the code for it. Toungue

I'll try to figure something out as I know it's possible to fix the problem. It's just a matter of how we approach it.
Best Regards.
Here's a fix with my idea:
In xmlhttp.php and newreply.php, find:
$message .= "[quote='{$quoted_post['username']}' pid='{$quoted_post['pid']}' dateline='{$quoted_post['dateline']}']\n{$quoted_post['message']}\n[/quote]\n\n";
Replace with
		if(my_strpos($quoted_post['username'], ']') !== false)
		{
			$quoted_post['username'] = '"'.$quoted_post['username'].'"';
		}
		$message .= "[quote={$quoted_post['username']} pid='{$quoted_post['pid']}' dateline='{$quoted_post['dateline']}']\n{$quoted_post['message']}\n[/quote]\n\n";

Will also need to patch inc/class_parser.php. There's quite a few modifications, so I'll give the functions you need to replace:
	/**
	* Parses quote MyCode.
	*
	* @param string The message to be parsed
	* @param boolean Are we formatting as text?
	* @return string The parsed message.
	*/
	function mycode_parse_quotes($message, $text_only=false)
	{
		global $lang, $templates, $theme, $mybb;

		// Assign pattern and replace values.
		$pattern = array(
			"#\[quote=((?:"|\"|')?)([^\"]*?)\\1([^]]*?)?\](.*?)\[\/quote\](\r\n?|\n?)#esi",
			"#\[quote\](.*?)\[\/quote\](\r\n?|\n?)#si"
		);

		if($text_only == false)
		{
			$replace = array(
				"\$this->mycode_parse_post_quotes('$4','$2$3')",
				"<blockquote><cite>$lang->quote</cite>$1</blockquote>\n"
			);
		}
		else
		{
			$replace = array(
				"\$this->mycode_parse_post_quotes('$4', '$2$3', true)",
				"\n{$lang->quote}\n--\n$1\n--\n"
			);
		}

		while(preg_match($pattern[0], $message) || preg_match($pattern[1], $message))
		{
			$message = preg_replace($pattern, $replace, $message);
		}

		if($text_only == false)
		{
			$find = array(
				"#(\r\n*|\n*)<\/cite>(\r\n*|\n*)#",
				"#(\r\n*|\n*)<\/blockquote>#"
			);

			$replace = array(
				"</cite><br />",
				"</blockquote>"
			);
			$message = preg_replace($find, $replace, $message);
		}
		return $message;
	}
	
	/**
	* Parses quotes with post id and/or dateline.
	*
	* @param string The message to be parsed
	* @param string The username to be parsed
	* @param boolean Are we formatting as text?
	* @return string The parsed message.
	*/
	function mycode_parse_post_quotes($message, $username, $text_only=false)
	{
		global $lang, $templates, $theme, $mybb;

		$linkback = $date = "";

		$message = trim($message);
		$message = preg_replace("#(^<br(\s?)(\/?)>|<br(\s?)(\/?)>$)#i", "", $message);

		if(!$message) return '';

		$message = str_replace('\"', '"', $message);
		$username = str_replace('\"', '"', $username);
		$delete_quote = true;

		preg_match("#\s*pid=((?:&quot;|\"|')?)([0-9]+)\\1#i", $username, $match);
		if(intval($match[2]))
		{
			$pid = intval($match[2]);
			$url = $mybb->settings['bburl']."/".get_post_link($pid)."#pid$pid";
			if(defined("IN_ARCHIVE"))
			{
				$linkback = " <a href=\"{$url}\">[ -> ]</a>";
			}
			else
			{
				eval("\$linkback = \" ".$templates->get("postbit_gotopost", 1, 0)."\";");
			}
			
			$username = str_replace($match[0], '', $username);
			$delete_quote = false;
		}

		unset($match);
		preg_match("#\s*dateline=((?:&quot;|\"|')?)([0-9]+)\\1#i", $username, $match);
		if(intval($match[2]))
		{
			if($match[2] < TIME_NOW)
			{
				$postdate = my_date($mybb->settings['dateformat'], intval($match[2]));
				$posttime = my_date($mybb->settings['timeformat'], intval($match[2]));
				$date = " ({$postdate} {$posttime})";
			}
			$username = str_replace($match[0], '', $username);
			$delete_quote = false;
		}
		
		// at this point, the message should already by htmlspecialchar'd, but we'll remove problematic characters in case they slip through
		$username = strtr($username, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;'));

		if($text_only)
		{
			return "\n".$username." $lang->wrote{$date}\n--\n{$message}\n--\n";
		}
		else
		{
			$span = "";
			if(!$delete_quote)
			{
				$span = "<span>{$date}</span>";
			}
			
			return "<blockquote><cite>{$span}".$username." $lang->wrote{$linkback}</cite>{$message}</blockquote>\n";
		}
	}
Pages: 1 2