This topic was marked solved by its starter, on June 7th, 2014, 08:28 PM

Infernus

  • Posts: 14
Possible js bug in admin panel
« on June 2nd, 2014, 05:49 PM »
Dont know if it's a bug, but it seems to appear in admin panel by using any browser. Affects javascript.

Browsers
Chrome:
(click to show/hide)
Code: [Select]
Uncaught SyntaxError: Unexpected token ILLEGAL index.php?action=admin:254
Code: [Select]
Google Chrome 35.0.1916.114 (Official build 270117) m
ОС Windows
Blink 537.36 (@173968)
JavaScript V8 3.25.28.16
Flash 13.0.0.214
User Agent Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36

Firefox:
(click to show/hide)
Code: [Select]
SyntaxError: unterminated string literal index.php:391
Code: [Select]
Mozilla firefox 29.0.1
ОС Windows
Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0

Opera:
(click to show/hide)
Code: [Select]
Uncaught SyntaxError: Unexpected token ILLEGAL index.php?action=admin:254
Code: [Select]
21.0.1432.67 - Opera
Stable
OC: Windows XP 32-bit
Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.132 Safari/537.36 OPR/21.0.1432.67


PHP Source:
(click to show/hide)
/app/Admin.php
Code: [Select]
// This sets the announcements and current versions themselves ;)
add_js('
new we_AdminIndex({
bLoadAnnouncements: true,
sAnnouncementTemplate: ', JavaScriptEscape('
<dl>
%content%
</dl>
'), ',
sAnnouncementMessageTemplate: ', JavaScriptEscape('
<dt><a href="%href%">%subject%</a> ' . sprintf($txt['on_date'], '%time%') . '</dt>
<dd>
%message%
</dd>
'), ',
sAnnouncementContainerId: \'wedge_news\',
sMonths: [\'', implode('\', \'', $txt['months']), '\'],
sMonthsShort: [\'', implode('\', \'', $txt['months_short']), '\'],
sDays: [\'', implode('\', \'', $txt['days']), '\'],
sDaysShort: [\'', implode('\', \'', $txt['days_short']), '\'],

bLoadVersions: true,
sVersionOutdatedTemplate: ' . JavaScriptEscape('
<span class="alert">%currentVersion%</span>
') . ',

bLoadUpdateNotification: true,
sUpdateTitle: ' . JavaScriptEscape($txt['update_available']) . ',
sUpdateMessage: ' . JavaScriptEscape($txt['update_message']) . ',
sUpdateLink: we_script + \'?action=admin;area=packages;pgdownload;auto;package=%package%;' . $context['session_query'] . '\'
});');

/app/Subs-Cache.php
Code: [Select]
/**
 * This function adds a string to the footer JavaScript that relies on jQuery and script.js being loaded.
 * Several strings can be passed as parameters, allowing for easier conversion from an "echo" to an "add_js()" call.
 */
function add_js()
{
global $context, $footer_coding;

if (empty($footer_coding))
{
$footer_coding = true;
$context['footer_js'] .= '
<script>';
}
$args = func_get_args();
$context['footer_js'] .= implode('', $args);
}

/app/Subs.php
Code: [Select]
/**
 * Sanitizes strings that might be passed through to JavaScript.
 *
 * Multiple instances of scripts will need to be adjusted through the codebase if passed to JavaScript through the template. This function will handle quoting of the string's contents, including providing the encapsulating quotes (so no need to echo '"', JavaScriptEscape($var), '"'; but simply echo JavaScriptEscape($var); instead.)
 *
 * Other protections include dealing with newlines, carriage returns (through suppression), single quotes, links, inline script tags, and SCRIPT. (Probably to prevent search bots from indexing JS-only URLs.)
 *
 * @param string $string A string whose contents to be quoted.
 * @param string $q (for quote) The quote character to use around the string. Defaults to '. Can be useful to switch to " if called within a string already declared with single quotes.
 * @return string A transformed string with contents suitably quoted for use in JavaScript.
 */
function JavaScriptEscape($string, $q = "'")
{
$xq = $q == '"' ? "\x0f" : "\x10";
return $xq . str_replace(
array('\\',   "\n",   'script',   'href=',   '"' . SCRIPT,         "'" . SCRIPT,         $q == '"' ? "'" : '"',       $q),
array('\\\\', "\\\n", 'scr\\ipt', 'hr\\ef=', '"' . SCRIPT . '"+"', "'" . SCRIPT . "'+'", $q == '"' ? "\x10" : "\x0f", '\\' . $xq),
$string
) . $xq;
}

Live source (code preview in browser):
(click to show/hide)
Code: [Select]
<script>
new we_AdminIndex({
bLoadAnnouncements: true,
sAnnouncementTemplate: '
\
<dl>
\
%content%
\
</dl>
\
',
sAnnouncementMessageTemplate: '
\
<dt><a hr\ef="%href%">%subject%</a> on %time%</dt>
\
<dd>
\
%message%
\
</dd>
\
',
sAnnouncementContainerId: 'wedge_news',
sMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
sMonthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
sDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
sDaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],

bLoadVersions: true,
sVersionOutdatedTemplate: '
\
<span class="alert">%currentVersion%</span>
\
',

bLoadUpdateNotification: true,
sUpdateTitle: 'Update Available!',
sUpdateMessage: 'You\'re using an outdated version of Wedge, which contains some bugs which have since been fixed.
\
It is recommended that you <a hr\ef="#" id="update-link">update your forum</a> to the latest version as soon as possible. It only takes a minute!',
sUpdateLink: we_script + '?action=admin;area=packages;pgdownload;auto;package=%package%;ca509c0=59cd8d0732ce33c0d7372308ebeed895'
});
new JumpTo("jump_to");
</script>

Farjo

  • "a valuable asset to the community"
  • Posts: 492
Re: Possible js bug in admin panel
« Reply #1, on June 7th, 2014, 04:54 PM »
What are the steps to recreate this? If it's just by going into the Admin panel then it's more likely to be a local problem as otherwise many people would be screaming about it!

Infernus

  • Posts: 14
Re: Possible js bug in admin panel
« Reply #2, on June 7th, 2014, 07:42 PM »Last edited on June 7th, 2014, 08:27 PM
It's just there when entering admin panel. It doesn't kill the experience of forum since it's just a js announcement, maybe that's why. Nobody notices it.

But how can a local server affect this? It's not even close. :unsure: Failing function is for sure JavaScriptEscape.

:edit: Seems to be a problem with line break character.
:edit: Fixed this error from appearing by removing line breaks from the script, seems like javascript don't like them.

Admin.php
Code: [Select]
// This sets the announcements and current versions themselves ;)
add_js('
new we_AdminIndex({
bLoadAnnouncements: true,
sAnnouncementTemplate: ', JavaScriptEscape('<dl>%content%</dl>'), ',
sAnnouncementMessageTemplate: ', JavaScriptEscape('<dt><a href="%href%">%subject%</a> ' . sprintf($txt['on_date'], '%time%') . '</dt><dd>%message%</dd>'), ',
sAnnouncementContainerId: \'wedge_news\',
sMonths: [\'', implode('\', \'', $txt['months']), '\'],
sMonthsShort: [\'', implode('\', \'', $txt['months_short']), '\'],
sDays: [\'', implode('\', \'', $txt['days']), '\'],
sDaysShort: [\'', implode('\', \'', $txt['days_short']), '\'],

bLoadVersions: true,
sVersionOutdatedTemplate: ' . JavaScriptEscape('<span class="alert">%currentVersion%</span>') . ',

bLoadUpdateNotification: true,
sUpdateTitle: ' . JavaScriptEscape($txt['update_available']) . ',
sUpdateMessage: ' . JavaScriptEscape($txt['update_message']) . ',
sUpdateLink: we_script + \'?action=admin;area=packages;pgdownload;auto;package=%package%;' . $context['session_query'] . '\'
});');

Admin.english.php
Code: [Select]
$txt['update_message'] = 'You\'re using an outdated version of Wedge, which contains some bugs which have since been fixed. It is recommended that you <a href="#" id="update-link">update your forum</a> to the latest version as soon as possible. It only takes a minute!';

:edit: Looks like solved.. purged cache <_<
:edit: Oh yeah, sexy announcements appeared. Thanks Nao ^_^

Farjo

  • "a valuable asset to the community"
  • Posts: 492
Re: Possible js bug in admin panel
« Reply #3, on June 7th, 2014, 08:36 PM »
Sorry - I didn't understand your first post. I thought you were getting an on-screen error when you went into Wedge's Admin screens ::)

Infernus

  • Posts: 14