Skip to content

Commit 8db8fc5

Browse files
authored
Merge pull request #1 from victornpb/fix-prototype-pullution
Fix prototype pullution
2 parents 786348a + 0175926 commit 8db8fc5

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

asciitable.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ function matrixToAsciiTable(m, options) {
3939
}, options);
4040

4141

42-
function defaults(c, b) {
43-
for (var a in b) {
44-
b.hasOwnProperty(a) && (c[a] && typeof b[a] === "object" ? defaults(c[a], b[a]) : c[a] = b[a]);
45-
}
46-
return c;
42+
function defaults(defaultObj, options) {
43+
var isObj = function (x) { return x !== null && typeof x === "object"; };
44+
if(isObj(options))
45+
for (var prop in defaultObj) {
46+
if (Object.prototype.hasOwnProperty.call(defaultObj, prop) && Object.prototype.hasOwnProperty.call(options, prop)) {
47+
if (isObj(defaultObj[prop])) defaults(defaultObj[prop], options[prop])
48+
else defaultObj[prop] = options[prop];
49+
}
50+
}
51+
return defaultObj;
4752
}
4853

54+
4955
function repeatStr(width, str) {
5056
str = str || " ";
5157
var result = (width > 0) ? Array(Math.ceil(width / str.length) + 1).join(str) : "";

asciitable.min.js

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

asciitable.umd.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@
4545
}, options);
4646

4747

48-
function defaults(c, b) {
49-
for (var a in b) {
50-
b.hasOwnProperty(a) && (c[a] && typeof b[a] === "object" ? defaults(c[a], b[a]) : c[a] = b[a]);
51-
}
52-
return c;
48+
function defaults(defaultObj, options) {
49+
var isObj = function (x) { return x !== null && typeof x === "object"; };
50+
if(isObj(options))
51+
for (var prop in defaultObj) {
52+
if (Object.prototype.hasOwnProperty.call(defaultObj, prop) && Object.prototype.hasOwnProperty.call(options, prop)) {
53+
if (isObj(defaultObj[prop])) defaults(defaultObj[prop], options[prop])
54+
else defaultObj[prop] = options[prop];
55+
}
56+
}
57+
return defaultObj;
5358
}
5459

60+
5561
function repeatStr(width, str) {
5662
str = str || " ";
5763
var result = (width > 0) ? Array(Math.ceil(width / str.length) + 1).join(str) : "";
@@ -115,6 +121,6 @@
115121
}
116122
return table.join(options.row.lineBreak);
117123
}
118-
124+
119125
return matrixToAsciiTable;
120126
}));

0 commit comments

Comments
 (0)