Skip to content

Fix for invalid processing of trailing / for JSON Pointer#411

Merged
stleary merged 1 commit into
stleary:masterfrom
johnjaylward:JSONPointerTrailingSlash
Mar 27, 2018
Merged

Fix for invalid processing of trailing / for JSON Pointer#411
stleary merged 1 commit into
stleary:masterfrom
johnjaylward:JSONPointerTrailingSlash

Conversation

@johnjaylward
Copy link
Copy Markdown
Contributor

@johnjaylward johnjaylward commented Mar 19, 2018

What problem does this code solve?
Fixes #410. String.split does not take into account trailing nulls when splitting. It instead trims them off and they are "lost".

Risks
Moderate. This is a bug fix to account for faulty processing of the token string in a JSONPointer expression. There is some change to existing behavior.

Changes to the API?
No

Will this require a new release?
Yes

Should the documentation be updated?
No

Does it break the unit tests?
Yes. One test case accidentally had a trailing / that causes an error with the corrected code. That test case has been corrected to use the correct JSONPointer expression. There were no unit tests to cover this type of input as expected input. New test cases have been created in stleary/JSON-Java-unit-test#85

Was any code refactored in this commit?
Yes. I replaced the String.split call with custom processing of the token string.

Review status
ACCEPTED
Changes to existing behavior are not usually accepted, but in this case the new code changes an edge case of a new feature. For more information please see the updated Wiki page: https://github.com/stleary/JSON-java/wiki/FAQ#what-kind-of-changes-will-be-accepted-for-this-project

@johnjaylward
Copy link
Copy Markdown
Contributor Author

@erosb Please review since you are most intimate with JSONPointer.

@johnjaylward johnjaylward force-pushed the JSONPointerTrailingSlash branch from edfbda0 to 2362c93 Compare March 19, 2018 13:57
@erosb
Copy link
Copy Markdown
Contributor

erosb commented Mar 20, 2018

Thank you for fixing this @johnjaylward . I'm a bit sorry to see there was no simpler way to do it.

Do you also plan to add a unittest?

@johnjaylward
Copy link
Copy Markdown
Contributor Author

New unit tests are available. I think I covered the cases.

@johnjaylward
Copy link
Copy Markdown
Contributor Author

There may be an easier way, but I figured this should be fast enough given how modern JVM and string library implementations handle substrings.

@stleary
Copy link
Copy Markdown
Owner

stleary commented Mar 21, 2018

@johnjaylward Breaks a unit test, can you investigate?
org.json.junit.JunitTestSuite > org.json.junit.JSONObjectTest.jsonObjectAppend FAILED
org.json.JSONPointerException at JSONObjectTest.java:670
Using the committed unit test code, not pull request 410.

@johnjaylward
Copy link
Copy Markdown
Contributor Author

The test was using incorrect syntax for the unit test. To get the item in a JSONArray at index 1 it was using /myArray/1/ but the trailing slash there is invalid for the data being expected. The Trailing / there indicates that we are looking for a JSONObject to be in the first index of the array and have a blank key "". However, the test actually wanted the value false.

I updated the test case and it should pass now.

@mfriedemann
Copy link
Copy Markdown

Hey, as reporter of #410 I can confirm that this proposed change fixes #410 and the issue in the actual code I was putting together.

Thanks,
M.

@erosb
Copy link
Copy Markdown
Contributor

erosb commented Mar 21, 2018

Hello, thank you for putting effort into fixing this.
I'm not at home this week and my current environment is not set up for looking into & testing the change locally, so feel free to proceed with opening the 3-day merge window.

@stleary
Copy link
Copy Markdown
Owner

stleary commented Mar 22, 2018

Accepted, starting 3 day comment window.

@stleary stleary merged commit bfb3008 into stleary:master Mar 27, 2018
@johnjaylward johnjaylward deleted the JSONPointerTrailingSlash branch March 27, 2018 13:28
erosb pushed a commit to everit-org/json-schema that referenced this pull request Mar 31, 2022
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.

JSON pointer query, trailing slashes and empty keys

4 participants