Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[fix] Fix broken circular reference tests without decycle

  • Loading branch information...
commit 4ca982165e31dc4cf10886c3fda26d06f8002862 1 parent 67955a9
@coderarity coderarity authored
View
19 lib/winston/common.js
@@ -66,7 +66,11 @@ exports.longestElement = function (xs) {
// Helper method for deep cloning pure JSON objects
// i.e. JSON objects that are either literals or objects (no Arrays, etc)
//
-exports.clone = function (obj) {
+exports.clone = function (obj, ctx) {
+ if (ctx === undefined || ctx === null) {
+ ctx = [ obj ];
+ }
+
// we only need to clone refrence types (Object)
if (!(obj instanceof Object)) {
return obj;
@@ -77,6 +81,11 @@ exports.clone = function (obj) {
var copy = {};
for (var i in obj) {
+ if (ctx.indexOf(obj[i]) >= 0) {
+ copy[i] = "[ Circular ]";
+ continue;
+ }
+
if (Array.isArray(obj[i])) {
copy[i] = obj[i].slice(0);
}
@@ -85,6 +94,14 @@ exports.clone = function (obj) {
}
else if (typeof obj[i] != 'function') {
copy[i] = obj[i] instanceof Object ? exports.clone(obj[i]) : obj[i];
+ if (obj[i] instanceof Object) {
+ ctx.push(obj[i]);
+ copy[i] = exports.clone(obj[i], ctx);
+ ctx.pop();
+ }
+ else {
+ copy[i] = obj[i];
+ }
}
}
View
3  lib/winston/transports/couchdb.js
@@ -66,6 +66,7 @@ Couchdb.prototype.log = function (level, msg, meta, callback) {
}
var self = this,
+ meta = common.clone(meta),
message = common.clone(meta || {}),
options,
req;
@@ -119,4 +120,4 @@ Couchdb.prototype.log = function (level, msg, meta, callback) {
// Always return true, regardless of any errors
callback(null, true);
-};
+};
View
1  lib/winston/transports/webhook.js
@@ -67,6 +67,7 @@ Webhook.prototype.log = function (level, msg, meta, callback) {
}
var self = this,
+ meta = common.clone(meta),
message = common.clone(meta),
options,
req;
Please sign in to comment.
Something went wrong with that request. Please try again.