Open osopolar opened 8 years ago
This seems to happen only at the end of the string and may be related to multi-byte characters. Could it be possible that the script reads stuff from memory where it shouldn't read or gets something that didn't get cleared probably?
I also saw this.
@netguy2k15 Do you have some more information which may help to reproduce this issue?
Now I just know that this function is invoked so many times, and Javascript also contains some multi-byte characters, let me try to reproduce it. Later I will also do some debugging.
Looks like if multi-byte characters is in a regular expression, it causes problems. Here is a related report: https://github.com/sqmk/pecl-jsmin/issues/44
If it's a regular expression, I suggest we just keep it and do not minify it.
Some updates: I fixed the regular issue and rebuilt, this can work, but it doesn't help the current problem.
Hello, I also have this issue. I sometimes get an unprintable char + a number after a }
or a ;
kind regards
There was this pull request #49 which was committed https://github.com/sqmk/pecl-jsmin/pull/49/commits/0a291e0eb520de03d96c1acf2300588541deca61 Maybe this affected this issue as well. Will try to give it a test and report back.
Issue #44 still occurs in the latest code base
Also affected.
I get the same problem. It is quite random. The source could be anything imported UTF-8 file, WIN-1252 or inline code written inside the PHP file. Depending how the script is written, the whole minified script could be invalid (e.g. anonymous or delta function).
The same page could be refreshed and the problem is now gone. Refreshing it again and the page could show another different set of characters. Sometimes, somehow, they are valid Javascript and allows the code to run unnoticed to the end user with the suffixed extra characters.
Thanks to @osopolar for the startup workaround, however sometimes the characters could be printable characters. For example, sometimes I get the ^n
at the end. I have improved the workaround like this:
$js=trim(jsmin(trim($js)));
//workaround for jsmin bug of random characters at the end
$l=substr($js,-1);
while(!empty($l) && $l!==';' && $l!=='}'){
$js=substr($js,0,-1);
$l=substr($js,-1);
}
This assumes that a valid good written script, the last character should be ;
or}
. Any other characters (control or printable) will be removed.
Did anyone every solve this in the actual c code?
Using JSMin in drupal module advagg, 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.
Other developers run into the same problem:
Workaround ($contents contains the minified js code):
See also issue https://www.drupal.org/node/2627468.