Skip to content

Commit

Permalink
sanitize: Moved stack.push/pop to the outer level.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Apr 7, 2014
1 parent 00bf1e2 commit 74d3dce
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/unexpected-core.js
Expand Up @@ -147,32 +147,27 @@
}
}

stack.push(obj);

var sanitized,
matchingCustomType = utils.findFirst(this.types || [], function (type) {
return type.identify(obj);
});
if (matchingCustomType) {
stack.push(obj);
sanitized = this.sanitize(matchingCustomType.toJSON(obj), stack);
stack.pop();
return sanitized;
}
if (isArray(obj)) {
stack.push(obj);
} else if (isArray(obj)) {
sanitized = map(obj, function (item) {
return this.sanitize(item, stack);
}, this);
stack.pop();
} else if (typeof obj === 'object' && obj) {
stack.push(obj);
sanitized = {};
forEach(getKeys(obj).sort(), function (key) {
sanitized[key] = this.sanitize(obj[key], stack);
}, this);
stack.pop();
} else {
sanitized = obj;
}
stack.pop();
return sanitized;
};

Expand Down

0 comments on commit 74d3dce

Please sign in to comment.