Skip to content

Conversation

@alshakero
Copy link
Collaborator

fixes #216

var results = new Array(patch.length);
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
results[i] = applyOperation(document, patch[i], validateOperation);
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cosmetics,
You can consider explaining why you hard-code one parameter and forward the others, as it caused me to think for a second.
Like, "mutateDocument was already covered for the entire sequence, we will apply operations on cloned document if applicable"

});
});

it(`should allow __proto__ modifications when the flag is set`, function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me more descriptive

Suggested change
it(`should allow __proto__ modifications when the flag is set`, function() {
it(`should allow __proto__ modifications when the mutateDocument flag is set`, function() {

expect(otherDoc.x).toEqual('polluted');
});

it(`should not allow __proto__ modifications without setting the flag and should throw an error`, function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it(`should not allow __proto__ modifications without setting the flag and should throw an error`, function() {
it(`should not allow __proto__ modifications without setting the mutateDocument flag and should throw an error`, function() {

jsonpatch.applyPatch(doc, patch);
} catch (e) {
expect(e.message).toEqual(expectedErrorMessage);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered expect(()=>{jsonpatch.applyPatch(doc, patch)}).to.throw(TypeError, expectedErrorMessage); to make test easier to read, and check for the error type as well?
https://www.chaijs.com/api/bdd/#method_throw

I'm afraid the code above would pass the test if jsonpatch.applyPatch(doc, patch); does not throw at all, as then the expect function is not called either.

@warpech
Copy link
Collaborator

warpech commented Mar 27, 2019

Please consider that PR #221 also proposes to change the signature of the method applyOperation

@alshakero
Copy link
Collaborator Author

Addressed all and tests are passing. merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent prototype injection

4 participants