Skip to content

Instantly share code, notes, and snippets.

@sherlock1982
Created October 26, 2018 11:53
Show Gist options
  • Save sherlock1982/7cfe81002a7183d43b01eb28cae310bf to your computer and use it in GitHub Desktop.
Save sherlock1982/7cfe81002a7183d43b01eb28cae310bf to your computer and use it in GitHub Desktop.
Uglify error sample
var input = 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));
};
function utf8_read_min(t, e, n) {
if (n - e < 1)
return "";
for (var r, i = null, o = [], s = 0; e < n; )
r = t[e++],
o[s++] = r < 128 ? r : 191 < r && r < 224 ? (31 & r) << 6 | 63 & t[e++] : 239 < r && r < 365 ? (r = ((7 & r) << 18 | (63 & t[e++]) << 12 | (63 & t[e++]) << 6 | 63 & t[e++]) - 65536,
o[s++] = 55296 + (r >> 10),
56320 + (1023 & r)) : (15 & r) << 12 | (63 & t[e++]) << 6 | 63 & t[e++],
8191 < s && ((i || (i = [])).push(String.fromCharCode.apply(String, o)),
s = 0);
console.log(o);
return i ? (s && i.push(String.fromCharCode.apply(String, o.slice(0, s))),
i.join("")) : String.fromCharCode.apply(String, o.slice(0, s))
};
utf8_read(input, 0, input.length);
utf8_read_min(input, 0, input.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment