MyBB Community Forums

Full Version: Bug Report with fix: mycode in email notifications
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
MyBB 1.8.14

MyBB is not removing mycode from email notifications of the posts that create a thread (it does so for replies).  In addition, it does not properly remove nested mycodes. The following chnages were made to resolve the issue.

inc/datahandlers/post.php:

Quote:<                 $excerpt = my_substr($thread['message'], 0, $mybb->settings['subscribeexcerpt']).$lang->emailbit_viewthread;
---
> // SPMOD: delay till later    $excerpt = my_substr($thread['message'], 0, $mybb->settings['subscribeexcerpt']).$lang->emailbit_viewthread;
>                 $excerpt = $thread['message'];
1617a1619,1621
>                 $excerpt = $parser->text_parse_message($excerpt);
>                 if (strlen($excerpt) > $mybb->settings['subscribeexcerpt'])
>                       $excerpt = my_substr($excerpt, 0, $mybb->settings['subscribeexcerpt']).$lang->emailbit_viewthread;

inc/class_parser.php: (the loop count limit can be any reasonable value and the count is there as a defensive programming failsafe to insure there is no infinite loop).
Quote:<         $message = preg_replace($find, $replace, $message);
---
>         $messageBefore = ""; 
>         for ($cnt = 1; $cnt < 5 && $message != $messageBefore; $cnt++) 
>         { 
>             $messageBefore = $message;
>             $message = preg_replace($find, $replace, $messageBefore);
>         }   
Thank You for reporting with possible fix. Our Developers will check it.
Yes, known issue Sad
An appendum to the needed fix. The class_parser needs to be fixed to also check for mycodes email, color, size, font, and align codes that have an "=" clause in them.  Fix involces adding a new second entry in the $find and $replace arrays.
		$find = array(
			"#\[(b|u|i|s|url|email|color|img)\](.*?)\[/\\1\]#is",
			"#\[(email|color|size|font|align|)=[^]]*\](.*?)\[/\\1\]#is",
			"#\[img=([1-9][0-9]*)x([1-9][0-9]*)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is",
			"#\[url=((?!javascript)[a-z]+?://)([^\r\n\"<]+?)\](.+?)\[/url\]#si",
			"#\[url=((?!javascript:)[^\r\n\"<&\(\)]+?)\](.+?)\[/url\]#si",
		);

		$replace = array(
			"$2",
			"$2",
			"$4",
			"$3 ($1$2)",
			"$2 ($1)",
		);
@azalea4va - is it a working fix?
I tested it on my experimental system and it worked (after I went back and fixed the second issue with "=" tags) but who knows what I might have missed. I have also implemented the fix on the system I am managing but my limited use site may go months before anybody makes a post that would contain anything that relates to this issue.

So yes it appears to be working but as with any code, so other testing would be useful.