Currently I get some console errors in Firefox and Chrome like "SyntaxError: illegal character", "Uncaught SyntaxError: Unexpected token ILLEGAL" or "SyntaxError: expected expression, got ')'". It seems there are some UTF-8 characters that don't belong there. I am still debugging the problem, but my guess it's because of some windows line endings in js-files (but it also happens for inline js).

@mikeytown2: In the issue #2566311-17: JSMin Compression destroy russian characters, you wrote that you have fun with UTF-8 and linked to the StackOverflow issue How to skip invalid characters in XML file using PHP. I was wondering if you have similar problems and/or if the problem is already known?

Comments

osopolar created an issue. See original summary.

osopolar’s picture

Priority: Critical » Normal
Status: Fixed » Active
osopolar’s picture

Issue summary: View changes
mikeytown2’s picture

I have not experienced what you're describing with console errors, thus it is unknown to me. The stack overflow code is used in our outbound XML service; we were getting some XML parsing errors on the receiving end due to copy paste characters getting in text fields. That stack overflow code is great for testing things as it can generate every single UTF-8 character and it can also filter out any UTF-8 character you want to.

I already filter out BOM

mikeytown2’s picture

How can I repo this bug?

osopolar’s picture

Title: Firefox console gives SyntaxError: illegal character » Browser console gives errores like SyntaxError: illegal character
Issue summary: View changes
mikeytown2’s picture

Status: Active » Postponed (maintainer needs more info)
osopolar’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new686 bytes

Actually I am not sure how to reproduce the error, as I can't find what is the cause of it (and the site is quiet large).

What I know so far is, that it seems to happen only with jsmin and the modifier options "Put a wrapper around inline JS if it was added in the content section incorrectly" and/or "Move all inline scripts to the bottom of the execution order" enabled.

Adding $contents = str_replace("\r", "", $contents); below the code which strips the Byte Order Marks in advagg_js_compress.advagg.inc seems to solve the problem, but I don't know why. Looking at the jsmin code it seems that \r gets replaced by \n, I can't imagine that this would cause any problems, but how knows?

Removing the code which strips the BOM $contents = str_replace(pack("CCC", 0xef, 0xbb, 0xbf), "", $contents); also solves the problem for me (it seems, that I have no js files with BOM).

Does this make any sense? I'll set up an minimal drupal installation to see if it happens there too and to find a recipe how to reproduce the problem.

osopolar’s picture

Status: Needs review » Needs work

I disabled advagg_mod and cleared the caches but the illegal character error didn't disappear. So it's not related to processing of inline scripts.

Removing \r as in #8 worked on my Ubuntu (15.10) development environment, but not on the stage server (Gentoo Base System). Removing the BOM removal code $contents = str_replace(pack("CCC", 0xef, 0xbb, 0xbf), "", $contents); will make the illegal characters disappear – but it doesn't make much sense to me, as the only js files with BOM in my project are the ckeditor scripts, which shouldn't be part of most pages/aggregates.

mikeytown2’s picture

steven jones’s picture

I've got this issue on my site at the moment, using advagg version 7.x-2.16.

I seem to get the 'ILLEGAL character' at the end of files that are being concatenated together when using the jsmin C extension.

On this specific file, I've got a semi-colon and another character:

;

Hex:

3B 0A

But in the aggregate that the file is built into I have:

;;;
/* S

Hex:

3B 01 0E 3B 3B 0A 2F 2A 20 53

(I've included up to the added source licensing comment)

steven jones’s picture

Oh, so upgraded to 2.17 and now have some of these in my log:

The jsmin function does not handle cyrillic characters. Using JSqueeze.

:(

I'll check installed versions of jsmin, I'm trying to use the C extension version.

steven jones’s picture

Yeah, jsmin 2.0.1.
They had gone away, but just flushed all caches, and the weird characters are back!

mikeytown2’s picture

Title: Browser console gives errores like SyntaxError: illegal character » JsMin: Browser console gives errors like SyntaxError: illegal character

  • NickWilde committed cbbc484 on 8.x-2.x
    Issue #2627468 by NickWilde, osopolar: JsMin: Browser console gives...

  • NickWilde committed c0716b9 on 7.x-2.x
    Issue #2627468 by NickWilde, osopolar: JsMin: Browser console gives...
nickdickinsonwilde’s picture

Status: Needs work » Fixed

Ran into this myself on a production site (D8) that I was updating AdvAgg on which already had JS minification active. I couldn't determine any reason it changed nor why it didn't show up on some of my test sites. However did confirm that is is not directly in AdvAgg - both JSqueeze and JSMin (2.0.1 at least) can do it including when called from a minimal PHP test script.

So added an extra check & fix to 8.x-2.x and back ported that to 7.x-2.x.

nickdickinsonwilde’s picture

Assigned: Unassigned » nickdickinsonwilde
Status: Fixed » Needs work

actually doesn't catch all cases...

nickdickinsonwilde’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev
StatusFileSize
new1.03 KB

There that gets all cases I've managed to generate.

nickdickinsonwilde’s picture

Status: Needs work » Fixed

  • NickWilde committed ed829fc on 8.x-2.x
    Issue #2627468 by osopolar, NickWilde: JsMin: Browser console gives...
nickdickinsonwilde’s picture

Version: 8.x-2.x-dev » 7.x-2.x-dev
Assigned: nickdickinsonwilde » mikeytown2
Status: Fixed » Needs review
StatusFileSize
new1.07 KB

New 7x patch.

mikeytown2’s picture

Status: Needs review » Fixed

Awesome! Thanks for the patch!

  • mikeytown2 committed 3891141 on 7.x-2.x authored by NickWilde
    Issue #2627468 by NickWilde: JsMin: Browser console gives errors like...
steven jones’s picture

Seems to be working for me. Thanks!

steven jones’s picture

Guessing we should try and get this fixed upstream in jsmin?

osopolar’s picture

Status: Fixed » Needs work

Thanks NickWilde for working on this.

In my case its not working. I updated the module, cleared all caches multiple times and also cleared advagg files (under AdvAgg: Operations > Drastic Measures). The error message "SyntaxError:illegal character" went away but I get for example the message "SyntaxError: missing ) in parenthetical" (Firefox)or "SyntaxError: Unexpected token ;" (Chrome) due to some other garbage between the javascript code from two different js source files like "(A;" in the following code sniped: (jQuery);;(A;(function ($) {

The code from the patch also assumes that everything after the last occurrence of ";" could be thrown away. But there could be a "}" after the last ";" (see for example advagg.admin.js) which should not be removed.

I also opened an issue for jsmin: https://github.com/sqmk/pecl-jsmin/issues/46.

@NickWilde: May you provide the "minimal PHP test script" which you mentioned in #17? This may help to find the cause of the problem.

mikeytown2’s picture

Status: Needs work » Needs review
StatusFileSize
new766 bytes

Fix for js ending with }.

mikeytown2’s picture

Assigned: mikeytown2 » Unassigned
osopolar’s picture

Thanks mikeytown2, this seems to work, the code makes sense. Anyway I'll observe the problem, as it disappeared once before (when I created patch from #8) and later it came back again.

osopolar’s picture

Status: Needs review » Needs work

It's still not working for me. Chrome gave me the error "Uncaught ReferenceError: A is not defined" due to this code snipped: (jQuery);;-A;(function ($) {.

mikeytown2’s picture

I wonder if we cutoff anything after the ; or } for every file, as in get rid of the if statement from the patch in #28.

mikeytown2’s picture

Status: Needs work » Needs review
StatusFileSize
new1015 bytes

Browsing around other js file and I do see some of them also end in ). Here's the idea from #32

osopolar’s picture

StatusFileSize
new1013 bytes

The problem is, that substr() isn't removing enough, as strrpos gives the position (start counting from 0) and substr third parameter requires a length (which should be position + 1). Simple example: If the string in $contents is just ; then strrpos($contents, ';'); will return 0, but it's length is 1.

Check also:

$contents = "var x=1;";
$a = strrpos($contents, ';');
$b = strrpos($contents, '}');
$c = strrpos($contents, ')');
$contents = substr($contents, 0, 1 + max($a, $b, $c));
dpm($contents);

I hope the patch now fixes the problem.

mikeytown2’s picture

Guessing #34 fixes it?

osopolar’s picture

So far it's working well for me.

mikeytown2’s picture

Status: Needs review » Reviewed & tested by the community
mikeytown2’s picture

Status: Reviewed & tested by the community » Fixed

#34 has been committed

  • mikeytown2 committed 95c0ec0 on 7.x-2.x authored by osopolar
    Issue #2627468 by osopolar, mikeytown2: JsMin: Browser console gives...
osopolar’s picture

Status: Fixed » Needs review
StatusFileSize
new1.27 KB

It worked well the last days on the test environment, but it occurred again today. Maybe the assumption "The first chars varies a bit but the last char is always an ASCII control character" is true for most cases but not for all. I added a patch that removes the if statement. See also #32.

mikeytown2’s picture

@osopolar
Let me know after a week or two if the patch in #40 is still working. It's a little risky but it should solve the issue, thus why I'm waiting before committing it.

mikeytown2’s picture

@osopolar
Is #40 still good?

ndobromirov’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

Hi all and thanks for the patch :),

I have updated from 2.17 (stable) to latest dev version due to this issue (unsuccessfully), the patch in #40 fixes it.
Moving to Major, as JS is broken on pages with advagg enabled.
Marking #40 as RTBC as it is a working fix.

I think this needs a stable in near future, as the 2.17 broken when using recommended settings (JSMin).

BR, Nikolay Dobromirov.

mikeytown2’s picture

Status: Reviewed & tested by the community » Fixed

@ndobromirov
Thanks for the feedback! Jsmin issue is here: https://github.com/sqmk/pecl-jsmin/issues/46

I've committed #40 with the addition of linking to the github issue as well.

andsigno82’s picture

hi,
when using curl "patchurl" | git apply -v

i'm getting this error

Checking patch advagg_js_compress/advagg_js_compress.advagg.inc...
error: while searching for:
return;
}

// Under some unknown/rare circumstances, JSMin and JSqueeze can add a
// couple of extraneous/wrong chars at the end of the string. Check and
// remove if necessary.
if (substr(trim($contents), -2) == "\xE3\x7F") {
$contents = substr($contents, 0, -2);
}

// Ensure that $contents ends with ; or }.

error: patch failed: advagg_js_compress/advagg_js_compress.advagg.inc:364
error: advagg_js_compress/advagg_js_compress.advagg.inc: patch does not apply

what I'm doing wrong?

mikeytown2’s picture

@andsigno82
Patch was rolled from dev, you're trying to patch 7.x-2.17. This has been committed (#44) so using the latest dev will have this patch already applied to it. Reason this conflicts is I committed a fix that worked in most cases in #24 and then #39. So to get this patch to apply to 2.17 you'll need to apply #22, #34 and then #40.

maxtorete’s picture

I installed the latest dev version but the problem persists. I'm getting this error:

Uncaught ReferenceError: V is not defined

And this is like the offending code looks like:

$('form.ctools-auto-submit-full-form',context).add('.ctools-auto-submit',context).filter('form, select, input:not(:text, :submit)').once('ctools-auto-submit').change(function(e){if($(e.target).is(':not(:text, :submit, .ctools-auto-submit-exclude)')){triggerSubmit.call(e.target.form);}});var discardKeyCode=[16,17,18,20,33,34,35,36,37,38,39,40,9,13,27];$('.ctools-auto-submit-full-form input:text, input:text.ctools-auto-submit',context).filter(':not(.ctools-auto-submit-exclude)').once('ctools-auto-submit',function(){var timeoutID=0;$(this).bind('keydown keyup',function(e){if($.inArray(e.keyCode,discardKeyCode)===-1){timeoutID&&clearTimeout(timeoutID);}}).keyup(function(e){if($.inArray(e.keyCode,discardKeyCode)===-1){timeoutID=setTimeout($.proxy(triggerSubmit,this.form),500);}}).bind('change',function(e){if($.inArray(e.keyCode,discardKeyCode)===-1){timeoutID=setTimeout($.proxy(triggerSubmit,this.form),500);}});});}}})(jQuery);;~	V;

If I disable the JS compression it works fine.

maxtorete’s picture

I deleted manually the folder sites/default/files/advagg_js and now it is working. I thought it should be deleted when clearing caches.

osopolar’s picture

Status: Fixed » Needs work

Sorry for late response. I switched the production environment to JSqueeze, as it didn't seem to be save using JSMin. I didn't expire any problems with JSqueeze (unlike to the experience in #17).

The testing environment I set to JSMin and today I got the warning SyntaxError: expected expression, got ')' again, due to the js code from devel module (devel_krumo_path.js): (jQuery);;);.

nickdickinsonwilde’s picture

@maxtorete ([#49]) - no that is not normally cleared, although AdvAgg does provide an easy way to clear it - under the settings - admin/config/development/performance/advagg/operations under 'drastic operations'

mikeytown2’s picture

@maxtorete
Clearing the caches does not delete files; you have to go to admin/config/development/performance/advagg/operations and under Drastic Measures click the button under "Clear All Files". This is something that is usually not needed.

@osopolar
File in question - http://cgit.drupalcode.org/devel/tree/devel_krumo_path.js?h=7.x-1.x. Super strange that ;); was added to it; seems like a parser bug in jsmin.

osopolar’s picture

Normally the JSMin fix seemed to worked fine, and maybe the error in #50 is something different. It occurred when the krumo js from devel was loaded. Would be nice if anybody who tested the fixes of this issue could check if krumo works well for them – just go to /devel/php, run the following code dpm(array(1,2)); and check the browsers console log.

@NickWilde: You said in #17 "However did confirm that is is not directly in AdvAgg - both JSqueeze and JSMin (2.0.1 at least) can do it including when called from a minimal PHP test script.". Would you be so kind and provide the minimal PHP test script, that might made it much easier to find the real error (in JSMin), as the above fixes are all just workarounds. Are you sure it happens in JSqueeze too? For me JSqueeze is working well. Maybe it just appeared for JSqueeze due to some caching?

@mikeytown2: Where you able to reproduce the problems with JSMin? For me it only happens on the stage (and live) server (Gentoo Linux) but not on the development environment (Ubuntu 15.10). Maybe there is something wrong with the server configuration.

osopolar’s picture

After the bulletproof cache clearing (drush advagg-clear-all-files && drush advagg-force-new-aggregates && drush cache-clear all) the error from #50 went away, now I get TypeError: (intermediate value)(...) is not a function, complaining the code: krumo.out=function(el){krumo.unclass(el,'krumo-hover');}(function($){Drupal.toggleFieldset=function(fieldset).

The problem goes away if I manually add a ";" after {krumo.unclass(el,'krumo-hover');} either in the aggregated file or in the original krumo.js. The code in advagg_get_js_aggregate_contents() should prevent the js files "from running together", but therefore the code $contents .= ";/**/\n"; should be called after drupal_alter('advagg_get_js_file_contents'), shouldn't it?

Looking at the source of krumo.js, there are many carriage returns signs (^M), so maybe the bug in JSMin is related to that?

mikeytown2’s picture

@mikeytown2: Where you able to reproduce the problems with JSMin?

I've never had this issue so I'm shooting in the dark.

osopolar’s picture

@mikeytown2: I remember that I read somewhere that the encoding passed to the pecl extension (in this case jsmin) depends on the locale settings of the machine where the code runs. On my test machine LANG is set to "en_US.ISO8859-1". You may try to set LANG="en_US.ISO8859-1" in /etc/default/locale and then check with locale in a new terminal window (or better restart the (web-) server). On my development environment it seems that it worked to trigger the problem, after disabling the fix $contents = substr($contents, 0, 1 + max($a, $b, $c));.

mikeytown2’s picture

@osopolar
Sounds like that is something I could check for on the status report page... good to know. We're using CentOS and you're using Ubuntu; this could explain a lot.

mikeytown2’s picture

@osopolar
what happens when you run locale on your sever? I get everything coming back as en_US.UTF-8.

osopolar’s picture

I get the following for the (managed) server where the problem occurred:

LANG=en_US.ISO8859-1
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

Not sure if/why LANG matters, as everything else is set to utf8 and afaik LANG provides only the default for the others (see man 7 locale). But when I changed to LANG=en_US.ISO8859-1 for my local development environment (see #56) I was able to reproduce the problem there too.

mikeytown2’s picture

Here's some code that should detect if the locale is not UTF-8

  if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
    $return = shell_exec('locale');
    $settings = parse_ini_string($return);
    foreach ($settings as $key => $value) {
      if (strpos($value, 'UTF-8') === FALSE) {
        echo "$key = $value is not UTF-8.<br>\n";
      }
    }
  }
osopolar’s picture

@mikeytown2: Where you able to reproduce the error by setting LANG=en_US.ISO8859-1 (see #56)?

Or could anybody else confirm that the problem is related to the locale settings?

ndobromirov’s picture

Hi again,

The fix from 40 was working until today.
After a new code was deployed to a staging environment the issue is back with different broken symbols.

The script from #60 outputs the following on that server:

  LANG = C is not UTF-8.
  LC_CTYPE = C is not UTF-8.
  LC_NUMERIC = C is not UTF-8.
  LC_TIME = C is not UTF-8.
  LC_COLLATE = C is not UTF-8.
  LC_MONETARY = C is not UTF-8.
  LC_MESSAGES = C is not UTF-8.
  LC_PAPER = C is not UTF-8.
  LC_NAME = C is not UTF-8.
  LC_ADDRESS = C is not UTF-8.
  LC_TELEPHONE = C is not UTF-8.
  LC_MEASUREMENT = C is not UTF-8.
  LC_IDENTIFICATION = C is not UTF-8.
  LC_ALL = is not UTF-8.
mikeytown2’s picture

ndobromirov
What's your linux distro and its version?

ndobromirov’s picture

cat /proc/version

  Linux version 2.6.32-504.12.2.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) ) #1 SMP Wed Mar 11 22:03:14 UTC 2015

cat /etc/*-release

  CentOS release 6.6 (Final)

Using PHP 5.5 with the REMI packages, nothing is compiled from source, so nothing is that custom.

mikeytown2’s picture

@ndobromirov
What do you get when you run locale -a?

ndobromirov’s picture

StatusFileSize
new7.56 KB

Hi it appears that it's utf8 and not UTF-8. See in the attached file (ndobromirov-locale--a-info.txt).

mikeytown2’s picture

Good to know! My server is also CentOS 6.6, so it seems the UTF8 naming scheme is caused by something else.

  if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
    $return = shell_exec('locale');
    $settings = parse_ini_string($return);
    foreach ($settings as $key => $value) {
      if (stripos($value, 'UTF-8') === FALSE && stripos($value, 'UTF8') === FALSE) {
        echo "$key = $value is not UTF 8.<br>\n";
      }
    }
  }
mikeytown2’s picture

Have a proof of concept code for checking the required min php version and the current jsmin version on github.

  $request = drupal_http_request('https://cdn.rawgit.com/sqmk/pecl-jsmin/master/package.xml');
  $string = $request->data;
  $dom = new DOMDocument();
  $dom->loadXML($string);
  $items = $dom->getElementsByTagName('php');
  foreach ($items as $item) {
    echo $item->nodeValue . "\n";
  }
  $items = $dom->getElementsByTagName('release');
  foreach ($items as $item) {
    echo $item->nodeValue . "\n";
  }

I gave a go at this with xpath queries but I didn't have any luck; I think this will work for now.

osopolar’s picture

<dependencies><required><php><min>5.4.0 does not mean that this is he minimum required php version for jsmin, it's just for Travis CI (see https://github.com/c9s/pecl-jsmin/commit/1971ecd075ab8d4749c2fbc2574fad7...). The readme says:

This extension currently works with PHP 5.3.10+. Support for older versions of PHP is not provided.

ndobromirov’s picture

So now it's only this:
LC_ALL = is not UTF 8.

I am with PHP 5.5 so I do not think it's PHP's version-related.

Is it possible the internal file encoding to cause the issue?
see this from the JSmin Home-page (http://crockford.com/javascript/jsmin):

Character Set:

JSMin requires, but does not verify, that the character set encoding of the input program is either ASCII or UTF-8. It might not work correctly with other encodings.

So if some of the source files internal encoding in the aggregates is different than UTF-8 it will be undefined/invalid input for JSMin.
I will try to see whether this is the problem is my case sometime today or tomorrow and keep you posted.

mikeytown2’s picture

Status: Needs work » Needs review
StatusFileSize
new680 bytes

Recently discovered http://php.net/setlocale. Does this fix the issue for people who are having jsmin issues?

mikeytown2’s picture

StatusFileSize
new3.83 KB

Here's the status report page patch.

  • mikeytown2 committed c0e7759 on 7.x-2.x
    Issue #2627468 by mikeytown2: Check jsmin version on github on the...
mikeytown2’s picture

Committed part of #73; the locale parts are now in this patch.

mikeytown2’s picture

I need someone with this issue to test #72 and advagg-2627468-74-status-report-locale.patch in #75. Looking like once I get #2376849: ReferenceError: krumo is not defined & fix js errors inside of krumo.js done I'll be tagging the next release of AdvAgg; I would like to include a better fix for the jsmin issue if at all possible.

ndobromirov’s picture

Hi, This is very strange...

Last time, I was able to reproduce this on all environments (local, integration, stage, life).
I can not reproduce this anywhere now, two weeks later, JSMin works... JMin is still 2.0.1. (4 month old stable release).

No changes were done on the server configurations, just some new code was deployed / developed.
It is custom module logic in pure PHP (cron process), in no way related to JS resources handling.

Keep you posted if this comes up in future and if the patch in#72 & #75 have any effect on fixing it.
At the moment everything works without the patch. Code is in the same state as it was in #40.

osopolar’s picture

I will test the patch this week.

As the bug does not always happen and not on every aggregation I think it would be a nice feature to have a syntax check for js files on the status page (and, if debug mode is enabled maybe also on every page request).

noahott’s picture

I was experiencing these "Uncaught SyntaxError: Unexpected token ILLEGAL" (Chrome) and SyntaxError: Invalid character '\u0008' (Safari) errors after moving a site from an Apache server to NGINX on Ubuntu 14.04. I was able to fix the problem by downgrading the PECL JSMin PHP extension from version 2.0.1 to 1.1.0. The PECL release notes mention adding UTF-8 support in version 2.0.0:

https://pecl.php.net/package-changelog.php?package=jsmin&release=2.0.0

mikeytown2’s picture

@noahott
If you go back to using 2.0.1 and apply #72 does that fix the issue for you? If not what does the status report say when you apply the 2nd patch of #75 (advagg-2627468-74-status-report-locale.patch)?

osopolar’s picture

Status: Needs review » Needs work
StatusFileSize
new2.62 KB

I updated advagg to the latest dev (7.x-2.17+65-dev) and applied both patches from #74.

The first surprising thing was the result from the status page:

The locale on your server is not UTF 8:

LC_CTYPE=POSIX is not UTF 8.
LC_NUMERIC=POSIX is not UTF 8.
LC_TIME=POSIX is not UTF 8.
LC_COLLATE=POSIX is not UTF 8.
LC_MONETARY=POSIX is not UTF 8.
LC_MESSAGES=POSIX is not UTF 8.
LC_PAPER=POSIX is not UTF 8.
LC_NAME=POSIX is not UTF 8.
LC_ADDRESS=POSIX is not UTF 8.
LC_TELEPHONE=POSIX is not UTF 8.
LC_MEASUREMENT=POSIX is not UTF 8.
LC_IDENTIFICATION=POSIX is not UTF 8.

I get this for both, the testing server and my local development environment (which is different to the result I get when I call locale directly from the cli). Anyway, it's nothing that I can control on the managed server (as the hosting company won't change it).

I added setlocale(LC_ALL, "en_US.UTF-8"); to the settings.php file, enabled jsmin and cleared caches multiple times and incremented global counter to force new aggregates. For some time it looked good, but than I got the same problem again as in #50.

BTW: The patch removes the
tags from the status page as they where printed in the status message.

mikeytown2’s picture

I was really hoping that setlocale would have fixed it. Changing the servers locale seems like a non starter so at this point I'm thinking of commenting out the latest github version check and pushing out a new advagg version.

  • mikeytown2 committed f56c9fa on 7.x-2.x
    Issue #2627468 by mikeytown2: Remove jsmin php extention version check...
mikeytown2’s picture

This code has been removed from the advagg_js_compress.install file as the 2.0.1 version seems to cause issues so recommending that people upgrade to it would be a bad idea at the moment.

  // Check locale and jsmin version.
  if ( function_exists('jsmin')
    && defined('PHP_VERSION_ID')
    && constant('PHP_VERSION_ID') >= 50310
  ) {
    // Check versions.
    $request = drupal_http_request('https://cdn.rawgit.com/sqmk/pecl-jsmin/master/package.xml', array(
      'timeout' => 10,
      'headers' => array('Connection' => 'close'),
    ));
    if (!empty($request->data) && $request->code == 200) {
      $string = $request->data;
      $dom = new DOMDocument();
      $dom->loadXML($string);
      $items = $dom->getElementsByTagName('release');
      $github_version = 0;
      foreach ($items as $item) {
        if (!empty($item->nodeValue) && preg_match("/[0-9]+/", $item->nodeValue)) {
          $github_version = $item->nodeValue;
          break;
        }
      }
      $jsmin_version = phpversion('jsmin');
      if (!empty($jsmin_version) && !empty($github_version) && version_compare($jsmin_version, $github_version, '<')) {
        $requirements['advagg_js_compress_jsmin_version'] = array(
          'title' => $t('AdvAgg JS Compressor'),
          'severity' => REQUIREMENT_WARNING,
          'value' => $t('jsmin should be upgraded.'),
          'description' => $t('There is a newer version of <a href="@url">jsmin</a> available. Server version: @server, Git hub version: @github', array(
            '@url' => 'https://github.com/sqmk/pecl-jsmin',
            '@server' => $jsmin_version,
            '@github' => $github_version,
          )),
        );
      }
    }
  }
sgdev’s picture

Similar to @noahott in #79, running Nginx with Ubuntu 14.04 and PHP 5.5. Had to downgrade from PECL JSMin 2.0.1 to 1.1.0, otherwise JS Compression is broken trying to use JSMin.

osopolar’s picture

@ron_s, @noahott: which module version of advagg where you using and may you post the line (or last characteristic part of the line where the error occurred)?

sgdev’s picture

@osopolar, I'm using 7.x-2.18. It's odd... JS compression was causing errors all over the site, so I downgraded to JSMin 1.1.0 and that fixed things. Now upgraded back to 2.0.1, and the site's JavaScript problems are no longer present.

Still getting errors at the command line when running drush updatedb or drush cc and a full cache clear is being done:

[notice] WD advagg_js_compress: The jsmin function does not exist. Using JSqueeze.                                                                                        [notice] WD advagg_js_compress: The jsmin function does not exist. Using JSqueeze.                                                                                        [notice] WD advagg_js_compress: The jsmin function does not exist. Using JSqueeze.                                                                                        [notice] WD advagg_js_compress: The jsmin function does not exist. Using JSqueeze.  

Downgrading to JSMin 1.1.0 fixes the command line error. I'll have to monitor and will post an update if I start seeing the JS errors return. (or maybe the JS errors won't return because the site is actually using JSqueeze at this point as a fall back?)

sgdev’s picture

Some additional information... I just put a few dpm's in advagg_js_compress_prep to see what is happening. If I have JSqueeze as the chosen compressor in /admin/config/development/performance/advagg/js-compress, I get that $compressor = 5 and function_exists('jsmin') = TRUE (as I would expect).

However, if I set JSMin as the chosen compressor, it looks like advagg_js_compress_prep is never run? I never get any result that the function is called. I haven't tracked up to see what might be causing that result, but just thought I would mention.

Edit: the function is being called, just looks like it required several cache clears to get it to run.

mikeytown2’s picture

Yeah was going to say that I cache css/js compression pretty heavily as they are expensive.

nickdickinsonwilde’s picture

StatusFileSize
new1003 bytes

Done a rather large degree of testing, manipulation and smashing my head into brick walls.
My results are so far not incredibly nice:
- yes the JsMin PHP extension has the problem without Drupal/AdvAgg
- it is close to random - at least I can't find any specific factor that ties them together
- The most freakish: sometimes just re-running on the same file directly after itself will fix it after 2 iterations or 4 or x.
- It can actually add pretty much any number of characters less than 5 - and they can be any character pretty much.

Despite those nasty results I have figured out changes to the post processing - a bit yucky but it works in all cases I've so far found/tested. I'll pop up a patch for 7x too shortly.

  • NickWilde committed 50df9fb on 8.x-2.x
    git commit -m 'Issue #2627468 by mikeytown2, osopolar, NickWilde: JsMin...
nickdickinsonwilde’s picture

Actually, I missed commit 8a896b8 in the 7x branch, @osopolar, did that sufficiently fix it for you?

sgdev’s picture

@NickWilde, is there a 7x branch commit for this issue? I'm looking for 8a896b8 and not seeing it... can you post a link? Thanks!

mikeytown2’s picture

mikeytown2’s picture

Status: Needs work » Postponed (maintainer needs more info)

Well going to postpone this for now, not much else we can do...

ndobromirov’s picture

Hi as far as I can see the fix is to downgrade to JsMin 1.1.0. I am testing on a new project now with the old version - no problems so far.

osopolar’s picture

@ndobromirov: The downside of downgrading to jsmin 1.1.0 is #2566311: JSMin Compression destroy russian characters.

manyk’s picture

It seems JsMin 2.0.1 generates this problem.
Downgrading to JsMin 2.0.0 solves the problem: no more "illegal character" errors.

loparr’s picture

I tried to downgrade to JsMi 2.0.0 but the "Uncaught SyntaxError: Unexpected token )" is stil there (and breaks views ui).
Chrome shows that the error is in my case in views-admin.js.
Looking at the compressed code, it seems that jsmin is making up some characters:

Original code:

jQuery(function() {
  jQuery(window).bind('resize', Drupal.viewsUi.resizeModal);
  jQuery(window).bind('scroll', Drupal.viewsUi.resizeModal);
});

Compressed code:
jQuery(function(){jQuery(window).bind('resize',Drupal.viewsUi.resizeModal);jQuery(window).bind('scroll',Drupal.viewsUi.resizeModal);});;);;

Notice the end of the compressed code.
Any workaround?

franckmarquis’s picture

I had a similar problem on some files with JSMin 2.0.1, and it had two different origins :

  • Some non visible characters (non-breaking spaces instead of regular spaces, made with "ALT-GR + SPACE" by developpers). These characters forced JSMin to fallback to JSSqueeze. Browsers seem to ignore non-breaking spaces and treat them as normal spaces, but JSMin didn't liked them.
  • "Uncaught SyntaxError: Unexpected token )". The javascript code came from an external lib (social-likes), and has code like this :
            if (rect.top < offset)
                elem.css('top', offset - rect.top + top);
            else if (rect.bottom > window.innerHeight - offset)
                elem.css('top', window.innerHeight - rect.bottom - offset + top);

Even if this code is valid, JSMin does like the fact that there is no "{" and "}" after "if" and "else".

Maybe it can help...

  • NickWilde committed 50df9fb on 8.x-3.x
    git commit -m 'Issue #2627468 by mikeytown2, osopolar, NickWilde: JsMin...
  • NickWilde committed cbbc484 on 8.x-3.x
    Issue #2627468 by NickWilde, osopolar: JsMin: Browser console gives...
  • NickWilde committed ed829fc on 8.x-3.x
    Issue #2627468 by osopolar, NickWilde: JsMin: Browser console gives...
mikeytown2’s picture

Status: Postponed (maintainer needs more info) » Active

I'm thinking this issue is the result of non UTF-8 js files not being converted correctly. I'll need to search thought the code base and have a wrapper for where file_get_contents is; making sure the encoding is correct.

mikeytown2’s picture

Status: Active » Needs review
StatusFileSize
new21.02 KB

  • mikeytown2 committed 3ba4509 on 7.x-2.x
    Issue #2627468 by mikeytown2, osopolar, NickWilde: JsMin: Browser...
mikeytown2’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.