Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to _jsonContains and _jsonContainsTypes to handle callbacks in nested objects and arrays #180

Closed

Conversation

marclitchfield
Copy link

This should fix #93 and #94

vlucas and others added 3 commits January 6, 2015 10:00
In _jsonContains and _jsonContainsTypes the arguments.callee.caller.name
check returns false when the functions recurse when evaluating callbacks
within nested objects. This fix will evaluate callbacks in nested objects
when the callee.name is the same as the caller.name.

This fix also evaluates callbacks within arrays by checking for the
"array" type.
@jkwohlfahrt
Copy link

Are there still plans to merge these fixes?

@@ -1217,7 +1217,7 @@ function _jsonContains(jsonBody, jsonTest) {
var keyType = jsonTest[key].prototype;

// User-supplied callback (anonymous function)
if(_toType(keyType) === "object" && arguments.callee.caller.name === "") {
if(_toType(keyType) === "object" && (arguments.callee.caller.name === "" || arguments.callee.caller.name === arguments.callee.name)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the argument.callee... part is removed in master; I'm not sure but it looks that it should be enough.

Copy link
Author

Choose a reason for hiding this comment

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

agreed; the original problem I was fixing here was that the comparison to empty string broke recursion, which resulted in deep objects not being compared. I verified that the changes on master pass the (non-array) tests in this PR, so this change should now be unnecessary.

@marcin-wosinek
Copy link
Collaborator

Looks that the very same issues was addressed in that commit:
bb82e8d

which is already on master.

@jkwohlfahrt, could you please check if it helps?

@marclitchfield
Copy link
Author

I'll close out this PR since it is pretty old, and master now has support for deep object comparisons. This PR also attempts to add support for array matchers, and in hindsight it is probably not appropriate to add this in the context of a bug fix. I'd suggest a new issue for array matchers could be opened up if that is something people would like to see, so we can discuss how (and if!) it might be implemented.

@marcin-wosinek
Copy link
Collaborator

Yes, matching whole array to with same element makes more sense. I've been confused by json-schema, because apparently there by default [{}, {}] checks element one by one.

Thanks for providing the PR!

@marclitchfield marclitchfield deleted the nested-objects-fix branch October 1, 2015 00:25
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.

expectJSONTypes: Can't use custom functions in nested objects
4 participants