ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Javascript Brackets Seen As EE Tags. EE 2.2 Bug?

June 30, 2011 3:08pm

Subscribe [6]
  • #1 / Jun 30, 2011 3:08pm

    toddajackson

    47 posts

    I’m on EE 2.2 and I’m seeing some strangeness with Javascript inside the system.

    For a global variable, I have an javascript ad code which has the following line in it:

    if (window.self != window.top) {nf=''} else {nf='NF/'};

    In previous version of EE this code worked, now it fails.

    In my console, javascript gives an error for it:

    Uncaught SyntaxError: Unexpected token else

    In the source code, I can see that this line has been changed at some point by EE to

    if (window.self != window.top)  else ;

    Effectively killing the code. It seems like EE thinks that {nf=''} and {nf='NF/'} are EE tags and attempts to replace them. Which is strange because it’s a Global Variable and really shouldn’t be parsed any more…

    I think this is a bug but is there anything else that could cause this?

  • #2 / Jul 01, 2011 1:59am

    John Henry Donovan

    12339 posts

    Hi Todd ,

    In your config.php file can you try setting the following please

    $config['debug'] = "1";

    Let us know if that makes a difference

  • #3 / Jul 01, 2011 2:03am

    toddajackson

    47 posts

    $config['debug'] = "1";

    Actually causes the problem. If I set it to “2”, the Javascript is parsed the way it should be.

    I have not upgrade to 2.2.1 yet. Will that help?

    Todd

  • #4 / Jul 01, 2011 2:05am

    John Henry Donovan

    12339 posts

    Todd,

    Yes please upgrade to latest. A good few bugs have been fixed for that release. Let us know if issue persists after upgrade.

  • #5 / Jul 01, 2011 3:13am

    narration

    773 posts

    Todd, I think you are changing the wrong debug setting compared to what John is asking for.

    Here’s an explanation of the two, and what is going on with config[‘debug’] as zero, which should help.

    By trying your string in both 2.2.0 and 2.2.1, I’ve also been able to see why people think Debug Preferences 2 helps, and will add that to the explanation.

    Setting $config[‘debug’] = “1”; in config.php is the one you want, and then Debug Preferences can go back to its normal 1 on the admin page, as it should be set.

    Regards,
    Clive

  • #6 / Jul 01, 2011 3:17am

    toddajackson

    47 posts

    I believe that the upgrade to 2.2.1 has solved this problem. When debug is set to 1, the javascript is parsed as expected.

  • #7 / Jul 01, 2011 3:21am

    toddajackson

    47 posts

    Todd, I think you are changing the wrong debug setting compared to what John is asking for.

    Here’s an explanation of the two, and what is going on with config[‘debug’] as zero, which should help.

    By trying your string in both 2.2.0 and 2.2.1, I’ve also been able to see why people think Debug Preferences 2 helps, and will add that to the explanation.

    Setting $config[‘debug’] = “1”; in config.php is the one you want, and then Debug Preferences can go back to its normal 1 on the admin page, as it should be set.

    Regards,
    Clive

    Clive,

    I’m not sure what you’re saying is applying to me. When I change the debug in the config, it’s also changed in the Admin automatically. If I changed it to “1”, it would show up as that in the Output and Debugging preferences. If I changed it to “2”, it would show up as “2” in the Output and Debugging Preferences.

    For me, they have been one and the same.

    Todd

  • #8 / Jul 01, 2011 3:22am

    narration

    773 posts

    Todd, I’m afraid that setting $config[‘debug’] = “1”; has always ‘fixed’ the problem.

    The problem actually occurs rather when this debug to “0”. It always has been so, back six months or more, and probably a lot longer than that.

    So, when people set “0” to prevent errors from a site from possibly showing errors, they also break [removed] block and JSON.

    That’s what’s breaking peoples’ sites, and is what we’re trying to get properly attended to and fixed.

    Regards,
    Clive

  • #9 / Jul 01, 2011 3:26am

    narration

    773 posts

    Clive,

    I’m not sure what you’re saying is applying to me. When I change the debug in the config, it’s also changed in the Admin automatically. If I changed it to “1”, it would show up as that in the Output and Debugging preferences. If I changed it to “2”, it would show up as “2” in the Output and Debugging Preferences.

    For me, they have been one and the same.

    Todd

    Ok, hang on a few moments. It’s late here, so let me just check what you say on the two versions where I have tests set up, before saying more.

    C.

  • #10 / Jul 01, 2011 3:26am

    toddajackson

    47 posts

    Clive,

    But I never had the debug set to “0” in either place. Not in the Config or the Admin area. I’m sure I had it set to “0” at one point and time… I think back when I was in 1.7.0

    Are you saying that by setting that by setting to “0” at any time breaks the [removed] block and JSON permanently?

    Todd

  • #11 / Jul 01, 2011 3:31am

    narration

    773 posts

    Yes, that’s it - $config[‘debug’] = “0”; always strips and breaks curly-bracketed Javascript (and anything else like that which hasn’t been parsed as an EE variable).

    It’s the only thing that can set off that stripper in the code.

    I would say that Debug Preference (in admin, and choice to show errors only to admins or to everyone (insecurely)) is a completely separate function—does differently.

    The only anomaly in this is that Debug Preference set to insecure 2 _will_ actually stop the breaking that config debug 0 causes in Javascript. _That_ I don’t yet understand, but it is true, and is why people both keep mentioning it and also get confused about the basis of the problem.

    Hope that’s clear?

    Clive

  • #12 / Jul 01, 2011 3:47am

    narration

    773 posts

    All right, Todd.

    Your observations have helped me nail precisely what is going on here, through testing, in this case on 2.1.1.

    - you are right, config[debug] and Debug Preferences are related: they change each other, some of the time, and actually are apparently intended to affect the same internal debug variable.

    - however, they actually do not act the same, and Debug Preferences is much in error. That’s why you guys see what you see.

    - I’ll make a clearer explanation on that other thread, to keep it together, and in the new bug report I’m going to file about this.

    The case, though, I think is solved.

    What I would recommend to you until it is fixed is to ignore Debug Preferences, and follow John’s advice by setting $config[‘debug’] = “1” in system/expressionengine/config/config.php.

    Now I’m going to write the reports, and get some sleep.

    Regards,
    Clive

  • #13 / Jul 05, 2011 5:29pm

    Brandon Jones

    5500 posts

    Hi all,

    We’ve posted a fix for sites being affected by this, and of course the fix will be rolled into the next release. If anyone is still having issues after replacing those three files, please let me know. Thanks!

  • #14 / Oct 10, 2011 8:12am

    wsmith

    13 posts

    I’m having the same problem with the latest build of EE 2.2.
    the code it is choking on is one of several simple EE “if” statements, some of which are inside javascript.

    I get:
    Uncaught SyntaxError: Unexpected token ==

    I have multiple If statements, many in javascript.

    after some research, i found that compound EE if statements (if/else type stuff) don’t work when embedded in javascript. I fixed that.
    also, i read in your knowledge base that sometimes it will happen if there isn’t whitespace around the EE statements. i fixed that.
    Then, i found this thread. even though I have the latest build, i fixed that.

    And still i get the error, or on a bad day i get this one:

    Parse error: syntax error, unexpected T_STRING

    uhuh.

  • #15 / Oct 11, 2011 4:11am

    John Henry Donovan

    12339 posts

    Hi wsmith,

    Can you share the template code that you are using?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases