-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* reproduce issue with test * reproduce issue with test * prettied and cleaned * improved code * remove empty line * code and test improvements * formatting
- Loading branch information
1 parent
01a4f4c
commit 8103e92
Showing
2 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -377,6 +377,10 @@ test("filter keys tests", function (t) { | |
}); | ||
var message = builder.build(); | ||
|
||
// Original object should not be modified | ||
t.equal(body.username, "[email protected]"); | ||
t.equal(body.password, "nice try"); | ||
|
||
t.test("form is filtered", function (tt) { | ||
tt.equal(message.details.request.form.username, undefined); | ||
tt.equal(message.details.request.form.password, undefined); | ||
|
@@ -399,6 +403,49 @@ test("filter keys tests", function (t) { | |
}); | ||
}); | ||
|
||
test("avoid infinite recursion in filter method", function (t) { | ||
let builder = new MessageBuilder({ | ||
filters: ["filtered"], | ||
}); | ||
|
||
// body self-references, causing a potential infinite recursion in the filter method | ||
// Causes exception: Maximum call stack size exceeded | ||
let body = { | ||
key: "value", | ||
filtered: true, | ||
}; | ||
// second level self-reference | ||
let other = { | ||
body: body, | ||
filtered: true, | ||
}; | ||
body.myself = body; | ||
body.other = other; | ||
|
||
let queryString = {}; | ||
let headers = {}; | ||
|
||
// performs filter on set | ||
builder.setRequestDetails({ | ||
body: body, | ||
query: queryString, | ||
headers: headers, | ||
}); | ||
var message = builder.build(); | ||
|
||
// key is preserved | ||
t.equal(message.details.request.form.key, "value"); | ||
// property in "filters" is filtered | ||
t.equal(message.details.request.form.filtered, undefined); | ||
t.equal(message.details.request.form.other.filtered, undefined); | ||
// self-referencing objects are also not included | ||
t.equal(message.details.request.form.myself, undefined); | ||
t.equal(message.details.request.form.other.body, undefined); | ||
|
||
// test should finish | ||
t.end(); | ||
}); | ||
|
||
test("custom tags", function (t) { | ||
t.test("with array", function (tt) { | ||
var builder = new MessageBuilder(); | ||
|