-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
json_pointer.contains() exception is incorrectly raised #1982
Comments
@RobBeyer Is your example json document correct? I'm not seeing an array there. |
Yes. The Reproduce Code Sample: |
The specification does not define how errors are handled. |
Well, if you want to try and explain the issue "backwards", then yes? At the moment, the When I do not want that invalid I want the |
As you said, the If yes, i think it is a good idea. |
No. That's not it at all. I do NOT want a try/catch around the The exception is being raised ONLY because the Even more explicit example: (showing
All of these are operating as expected. They return false BECAUSE the path is not CONTAINED in the object.
My point is that the Basically, That the path can not be (legally) evaluated by the input json object, is not what |
@dota17 - I believe that adding tests similar to the patch I proposed in #1942 would be much more appropriate than catching exception cases after attempting a path evaluation. Your proposed commit is (again) only testing the object against the path, instead of testing if the path is contained. If I wanted this type of an "exception handled" case, I could just eval the path against the object, and catch the exception myself and therefore assume that the path is not contained. Exceptions should be exceptional, not used for something expected. The #1942 proposed patch does not perform any further path checking, if the next element in the path (already having been identified as an array) can not possibly be contained in the object under test. A fix using this methodology would be not only more efficient than trying to evaluate, and then catch exceptions, but it can ensure that the path is "not contained" in the object. |
@RobBeyer If we add more tests to check, it will be a lot of added code. Thus, i push the work to |
Fine, I will update and add complete check to deal with |
@dota17 In those cases |
I had update my code and all testcases passed. Just consider the ABNF in RFC 6901 Sect 4. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
fix #1982:json_pointer.contains() exception is incorrectly raised
When using
contains()
with a_json_pointer
, if the json object being tested has an array in the path, the_json_pointer
is incorrectly being restricted to reference an array by the contents of the object, instead of verifying that the_json_pointer
is contained in the provided json object.The operation of
contains()
demonstrates the following bug:contains()
must validate if a_json_pointer
exists in a json object.contains()
must not validate if a_json_pointer
may not exist in a json object.contains()
must never raise an exception if a_json_pointer
can not be supported by a json object.To reproduce:
Current Behavior:
Expected Behavior:
Compiler: MSVC 2017, GCC
This bug is present in v3.7.3 / master.
Originally submitted as a question, but there has been no discussion for a month: #1942
I believe that RFC 6901 confirms this to be a bug - in that for the
contains()
operation, the_json_pointer
is NOT being EVALUATED at each depth in the path, but the path existence is being tested at each depth. The operation performed is to verify if the pointer is CONTAINED in the object under test. Therefore,contains()
pointer path processing should simply stop in this case, and no exception is to be raised.Background: RFC 6901 on _json_pointer
Section 4:
Section 7:
The text was updated successfully, but these errors were encountered: