Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uglifyjs breaks code on when sequences option on #3288

Closed
sherlock1982 opened this issue Oct 26, 2018 · 2 comments
Closed

Uglifyjs breaks code on when sequences option on #3288

sherlock1982 opened this issue Oct 26, 2018 · 2 comments

Comments

@sherlock1982
Copy link

sherlock1982 commented Oct 26, 2018

Bug

Uglify version 3.4.9

JavaScript input

var input1 = Array.from([17, 240, 159, 152, 128, 32]);

function utf8_read(buffer, start, end) {
    var len = end - start;
    if (len < 1)
        return "";
    var parts = null,
        chunk = [],
        i = 0, // char offset
        t;     // temporary
    while (start < end) {
        t = buffer[start++];
        if (t < 128)
            chunk[i++] = t;
        else if (t > 191 && t < 224)
            chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
        else if (t > 239 && t < 365) {
            t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
            chunk[i++] = 0xD800 + (t >> 10);
            chunk[i++] = 0xDC00 + (t & 1023);
        } else
            chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
        if (i > 8191) {
            (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
            i = 0;
        }
    }
    if (parts) {
        if (i)
            parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
        return parts.join("");
    }
    console.log(chunk);
    return String.fromCharCode.apply(String, chunk.slice(0, i));
};

utf8_read(input1, 0, input1.length);

CLI command executed

 node index.js && node_modules\.bin\uglifyjs index.js -c sequences > index.min.js && node index.min.js

This works:

  node index.js && node_modules\.bin\uglifyjs index.js -c sequences=false > index.min.js && node index.min.js

JavaScript output or error produced.

Actual output (of minified file):

[ 17, 56832, 55357, 32 ]

Expected output (of original file):

[ 17, 55357, 56832, 32 ]
@sherlock1982 sherlock1982 changed the title Uglifyjs breaks code on compress Uglifyjs breaks code on when sequences option on Oct 26, 2018
@kzc
Copy link
Contributor

kzc commented Oct 26, 2018

Dup of #3245 #3257 #3260 #3269 #3271 #3278

Either lock in uglify-js@3.4.8 or disable the compress option conditionals.

@nylen
Copy link

nylen commented Nov 9, 2018

Releasing a new version and then disappearing is bad form. Please follow up with your community after the release.

If you don't have time to do that, better not to do the release in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants