[Pkg-javascript-commits] [node-clean-yaml-object] 02/21: fix: StackOverrun when object.prop === object.

Bastien Roucariès rouca at moszumanska.debian.org
Thu Sep 7 09:52:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-clean-yaml-object.

commit 9a7466e9b6d3d72acc7ea5878575978aa490cb78
Author: James Talmage <james at talmage.io>
Date:   Fri Jan 15 22:09:38 2016 -0500

    fix: StackOverrun when object.prop === object.
---
 index.js | 6 +++---
 test.js  | 8 +++++++-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/index.js b/index.js
index 402f583..1cabd6f 100644
--- a/index.js
+++ b/index.js
@@ -3,8 +3,6 @@ module.exports = function (object, filterFn) {
 	return cleanYamlObj(object, filterFn || defaultFilter, true, []);
 };
 
-// Copied verbatim from node-tap:
-// https://github.com/isaacs/node-tap/blob/e9fdcdec5914204e814f922e7e677aff6d1ffc9e/lib/test.js#L1076-L1159
 function cleanYamlObj(object, filter, isRoot, seen) {
 	if (object === undefined) {
 		return null;
@@ -14,6 +12,8 @@ function cleanYamlObj(object, filter, isRoot, seen) {
 		return object.toString();
 	}
 
+	seen = seen.concat([object]);
+
 	if (Buffer.isBuffer(object)) {
 		return 'Buffer\n' + object.toString('hex').split('')
 				.reduce(function (set, c) {
@@ -102,7 +102,7 @@ function cleanYamlObj(object, filter, isRoot, seen) {
 
 function setProp(propName, source, target, seen, filter) {
 	if (seen.indexOf(source[propName]) === -1) {
-		target[propName] = cleanYamlObj(source[propName], filter, false, seen.concat([source]));
+		target[propName] = cleanYamlObj(source[propName], filter, false, seen);
 	} else {
 		target[propName] = '[Circular]';
 	}
diff --git a/test.js b/test.js
index 07e80ad..27e3d46 100644
--- a/test.js
+++ b/test.js
@@ -89,7 +89,13 @@ test('should only destroy parent references', t => {
 	t.is(serialized.two.secondThing.thing, '[Circular]');
 });
 
-test.skip('should work on arrays', t => {
+test('works if its own parent', t => {
+	const obj = {};
+	obj.parent = obj;
+	t.same(fn(obj), {parent: '[Circular]'});
+});
+
+test('should work on arrays', t => {
 	const obj = {};
 	const common = [obj];
 	const x = [common];

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-clean-yaml-object.git



More information about the Pkg-javascript-commits mailing list