Simple Machines Community Forum

SMF Development => Bug Reports => Fixed or Bogus Bugs => Topic started by: nend on November 25, 2015, 08:25:30 PM

Title: MessageIndex.php parsing twice possibility
Post by: nend on November 25, 2015, 08:25:30 PM
In MessageIndex.php if a topic has no replies and preview is enabled the message body is parse twice.

Here is the code section, if the topic has no replies $row['first_body'] and $row['last_body'] will be exactly the same.
            if (!empty($modSettings['preview_characters']))
            {
                // Limit them to $modSettings['preview_characters'] characters
                $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
                if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters'])
                    $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
                $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
                if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters'])
                    $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
                // Censor the subject and message preview.
                censorText($row['first_subject']);
                censorText($row['first_body']);
                // Don't censor them twice!
                if ($row['id_first_msg'] == $row['id_last_msg'])
                {
                    $row['last_subject'] = $row['first_subject'];
                    $row['last_body'] = $row['first_body'];
                }
                else
                {
                    censorText($row['last_subject']);
                    censorText($row['last_body']);
                }
            }

Here is the area where it is done twice in this situation.
                $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
                if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters'])
                    $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
                $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
                if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters'])
                    $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';

I think this
                $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
                if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters'])
                    $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';

Should be moved to the last else in the first code snipplet.
                else
                {
                    censorText($row['last_subject']);
                    censorText($row['last_body']);
                }

Not a real big deal though, but figured it was worth the mention.

*edit I said if a topic has no subject in the top, meant no replies.
Title: Re: MessageIndex.php parsing twice possibility
Post by: nend on April 01, 2016, 01:24:04 AM
This has been fixed in 2.1.
https://github.com/SimpleMachines/SMF2.1/commit/9162457f13740472bd5e5f8515685c5fd61ec590

Not sure though in 2.0.x