Skip to content

Commit 6f642e9

Browse files
committed
Use Buffer.from on Node > 5.10 to get rid of deprecation
1 parent f75f700 commit 6f642e9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ validateMapping = function (mapping) {
4141
}
4242
};
4343

44+
createBuffer = function (str, encoding) {
45+
// [DEP0005] Buffer() is deprecated due to security and usability issues
46+
// https://nodejs.org/api/buffer.html#buffer_new_buffer_array
47+
// Preserving backward compatibility until dropping Node version prior to v5.10.0
48+
return Buffer.hasOwnProperty('from') ? Buffer.from(str, encoding) : new Buffer(str, encoding);
49+
};
50+
4451
// Validates an entire sourcemap
4552
validate = function (min, map, srcs) {
4653
var consumer
@@ -55,7 +62,7 @@ validate = function (min, map, srcs) {
5562
var re = /\s*\/\/(?:@|#) sourceMappingURL=data:application\/json;base64,(\S*)$/m
5663
, map = min.match(re);
5764

58-
map = (new Buffer(map[1], 'base64')).toString();
65+
map = createBuffer(map[1], 'base64').toString();
5966
min = min.replace(re, '');
6067
}
6168
catch (e) {

0 commit comments

Comments
 (0)