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

Fix deprecated Buffer constructor usage and add safeguards #2947

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/minify.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
"use strict";

var to_ascii = typeof atob == "undefined" ? function(b64) {
return new Buffer(b64, "base64").toString();
if (Buffer.from && Buffer.from !== Uint8Array.from) {
// Node >= 4.5.0
return Buffer.from(b64, "base64").toString();
} else {
// Node < 4.5.0, old API, manual safeguards
if (typeof b64 !== "string") throw new Errror("\"b64\" must be a string");
return new Buffer(b64, "base64").toString();
}
} : atob;
var to_base64 = typeof btoa == "undefined" ? function(str) {
return new Buffer(str).toString("base64");
if (Buffer.from && Buffer.from !== Uint8Array.from) {
// Node >= 4.5.0
return Buffer.from(str, "ascii").toString("base64");
} else {
// Node < 4.5.0, old API, manual safeguards
if (typeof str !== "string") throw new Errror("\"str\" must be a string");
return new Buffer(str).toString("base64");
}
} : btoa;

function read_source_map(code) {
Expand Down