MyBB Community Forums

Full Version: JS error - modal template in headerinclude
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In MyBB 1.8.20 if the modal template was edited (or just saved) in the ACP, the following error is displayed in the browser console:

"SyntaxError: ' ' string literal contains an unescaped line break".

because the modal template content in headerinclude contains line breaks before and after the backslashes:
var templates = {
 modal: '<div class=\"modal\">
    \
    <div style=\"overflow-y: auto; max-height: 400px;\">
    \
        <table border=\"0\" cellspacing=\"0\" cellpadding=\"5\" class=\"tborder\">
    \
            <tr>
    \
                <td class=\"thead\" colspan=\"2\"><strong>__message__</strong></td>
    \
            </tr>
    \
            <tr>
    \
                <td colspan=\"2\" class=\"trow1\">
    \
                <div style=\"text-align: center\" class=\"modal_buttons\">__buttons__</div></td>
    \
            </tr>
    \
        </table>
    \
    </div>
    \
</div>',

Steps to reproduce:
Go to your ACP, edit and save "modal" Template, reload your forum, check browser console.

It seems templates  saved via ACP have different line breaks than the templates imported from XML files.

Proposed fix:
In global.php (lines 941-945) replace:
$jsTemplates = array();
foreach (array('modal', 'modal_button') as $template) {
    eval('$jsTemplates["'.$template.'"] = "'.$templates->get($template, 1, 0).'";');
    $jsTemplates[$template] = str_replace("\n", "\\\n", addslashes($jsTemplates[$template]));
} 

with:
$jsTemplates = array();
foreach (array('modal', 'modal_button') as $template) {
     eval('$jsTemplates["'.$template.'"] = "'.$templates->get($template, 1, 0).'";');
     $jsTemplates[$template] = str_replace(array("\n","\r"), array("\\\n", ""), addslashes($jsTemplates[$template]));
} 
You are right, this was missed Sad
Good catch, I'll push this.
Hi,

Thank you for your report. We have pushed this issue to our Github repository for further analysis where you can track our commits and progress with fixing this bug. Discussions regarding this bug may also take place there too.

Follow this link to visit the issue on Github: https://github.com/mybb/mybb/issues/3636

Thanks for contributing to MyBB!

Regards,
The MyBB Group