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

json: Fix multidimensional array support #50816

Merged
merged 6 commits into from
Jun 29, 2023

Conversation

mrfuchs
Copy link
Contributor

@mrfuchs mrfuchs commented Sep 29, 2022

This patch fixes support for encoding and decoding multidimensional arrays
as described by the JSON_OBJ_DESCR_ARRAY_ARRAY() macro.

Fixes #50801

@carlescufi
Copy link
Member

@mrfuchs can you take a look at the CI failures?

@mrfuchs mrfuchs force-pushed the json_arr-arr branch 3 times, most recently from f13877f to 5217b6a Compare October 4, 2022 13:44
andyross
andyross previously approved these changes Oct 4, 2022
Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

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

Saw this languishing and figured I should give it an approval, even though it's not really my area (we don't really have a maintainer for JSON right now, I guess?).

Language wonks (@stephanosio @keith-packard ?) might care about the unicode string literals, though they seem harmless to me.

tests/lib/json/src/main.c Outdated Show resolved Hide resolved
@dariis
Copy link
Collaborator

dariis commented Dec 2, 2022

@mrfuchs Thank you, it worked for me 👍

@mrfuchs
Copy link
Contributor Author

mrfuchs commented Dec 5, 2022

Saw this languishing and figured I should give it an approval, even though it's not really my area

Thank you! Unfortunately, I had to update this PR. Would you review it once more, please?

(we don't really have a maintainer for JSON right now, I guess?).

Yes, it's difficult to get JSON PRs approved - my last PR #47989 also got closed due to a lack of reviewers.
@Sir-Branch asked for being the official JSON maintainer, but has become inactive lately. Sometimes @martinjaeger helps reviewing changes to the JSON library.

Language wonks (@stephanosio @keith-packard ?) might care about the unicode string literals, though they seem harmless to me.

I didn't really pay attention to that. I just reused the test data that was already there.

@mrfuchs
Copy link
Contributor Author

mrfuchs commented Dec 5, 2022

I noticed that my original patch would still not fix parsing arrays of objects. That's why I moved these lines inside the loop...

zephyr/lib/os/json.c

Lines 578 to 583 in 55dc398

/* For nested arrays, update value to current field,
* so it matches descriptor's offset to length field
*/
if (elem_descr->type == JSON_TOK_ARRAY_START) {
value = field;
}

... and added a test for it (cf96b83). However, after adding the new unit test, CI failed again (for 64-bit targets only, cf. #36696 and #24372#issuecomment-617392567). So, I fixed this issue in 55dc398 to make CI work again.

@github-actions
Copy link

github-actions bot commented Feb 4, 2023

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@ofirshe
Copy link

ofirshe commented Jun 26, 2023

Hey,

I would like to inquire about the current status of this fix as I am experiencing the same issue as described here [(https://github.com//issues/59445)].

@mrfuchs
Copy link
Contributor Author

mrfuchs commented Jun 26, 2023

I would like to inquire about the current status of this fix as I am experiencing the same issue [...]

Will update this PR soon to follow @keith-packard's suggestion re. non-ascii text in the unit tests.

@mrfuchs mrfuchs force-pushed the json_arr-arr branch 2 times, most recently from 14b6bc0 to a0d34b3 Compare June 27, 2023 11:13
@mrfuchs
Copy link
Contributor Author

mrfuchs commented Jun 27, 2023

@andyross, @keith-packard, I updated the unit tests. Could you review? Thanks!

Copy link
Collaborator

@keith-packard keith-packard left a comment

Choose a reason for hiding this comment

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

The commit message on the first patch (fixing the bugs) provides no information about what was broken and how the change addresses that. Makes reviewing the patch pretty hard.

@keith-packard
Copy link
Collaborator

@andyross, @keith-packard, I updated the unit tests. Could you review? Thanks!

Unit test changes to use octal escapes look good!

This patch fixes support for encoding and decoding multidimensional arrays
as described by the JSON_OBJ_DESCR_ARRAY_ARRAY() macro.

Currently, the JSON array encoding and decoding functions, arr_encode()
and arr_parse(), expect array elements to be of object or primitive type.
However, arrays may be nested and so an array's elements may also be
arrays.

In order to support nested arrays, two special cases must be considered:

1. The array of objects/arrays sub-descriptor is described by two
`json_obj_descr` structs and so two instead of one `json_obj_descr`
structs must be skipped when iterating over the JSON descriptor to get to
an array's elements.
2. The implicit array item count field has to be considered for the
parent itself and all its child array items when calculating an element's
size.

Fixes zephyrproject-rtos#50801

Signed-off-by: Markus Fuchs <[email protected]>
Switch the non-ascii text in the tests to use octal escape sequences
to avoid potential compiler issues on platforms not defaulting to
utf-8 text encodings.

Signed-off-by: Markus Fuchs <[email protected]>
Fix encoded JSON string in test_json_decoding_array_array() test so it
matches the described array object and add a test case for encoding
arrays of arrays.

Signed-off-by: Markus Fuchs <[email protected]>
Add tests for encoding and decoding two-dimensional arrays as described by
the JSON_OBJ_DESCR_ARRAY_ARRAY() macro.

Signed-off-by: Markus Fuchs <[email protected]>
Add tests for encoding and decoding nested arrays of objects located
inside a parent object at a non-zero offset.

Signed-off-by: Markus Fuchs <[email protected]>
This patch fixes encoding arrays of objects on 64-bit targets.

Fixes zephyrproject-rtos#36696

Signed-off-by: Markus Fuchs <[email protected]>
@mrfuchs
Copy link
Contributor Author

mrfuchs commented Jun 28, 2023

The commit message on the first patch (fixing the bugs) provides no information about what was broken and how the change addresses that.

I updated the commit message so it contains more information on what was missing and what was changed.

@carlescufi carlescufi merged commit 8757c71 into zephyrproject-rtos:main Jun 29, 2023
17 checks passed
nandojve added a commit to nandojve/zephyr that referenced this pull request Apr 27, 2024
After the changes introduced by zephyrproject-rtos#50816 the UpdateHub could not decode
anymore the JSON object. This introduce missing parsing definitions
to allow JSON parser undertood the correct UpdateHub probe object.

Fixes zephyrproject-rtos#69297

Signed-off-by: Gerson Fernando Budke <[email protected]>
nandojve added a commit to nandojve/zephyr that referenced this pull request Apr 30, 2024
After the changes introduced by zephyrproject-rtos#50816 the UpdateHub could not decode
anymore the JSON object. This introduce missing parsing definitions
to allow JSON parser undertood the correct UpdateHub probe object.

Fixes zephyrproject-rtos#69297

Signed-off-by: Gerson Fernando Budke <[email protected]>
carlescufi pushed a commit that referenced this pull request May 2, 2024
After the changes introduced by #50816 the UpdateHub could not decode
anymore the JSON object. This introduce missing parsing definitions
to allow JSON parser undertood the correct UpdateHub probe object.

Fixes #69297

Signed-off-by: Gerson Fernando Budke <[email protected]>
nandojve added a commit to nandojve/zephyr that referenced this pull request May 7, 2024
After the changes introduced by zephyrproject-rtos#50816 the UpdateHub could not decode
anymore the JSON object. This introduce missing parsing definitions
to allow JSON parser undertood the correct UpdateHub probe object.

Fixes zephyrproject-rtos#69297

Signed-off-by: Gerson Fernando Budke <[email protected]>
(cherry picked from commit 5fb62ca)
nandojve added a commit that referenced this pull request May 7, 2024
After the changes introduced by #50816 the UpdateHub could not decode
anymore the JSON object. This introduce missing parsing definitions
to allow JSON parser undertood the correct UpdateHub probe object.

Fixes #69297

Signed-off-by: Gerson Fernando Budke <[email protected]>
(cherry picked from commit 5fb62ca)
mariopaja pushed a commit to mariopaja/zephyr that referenced this pull request May 26, 2024
After the changes introduced by zephyrproject-rtos#50816 the UpdateHub could not decode
anymore the JSON object. This introduce missing parsing definitions
to allow JSON parser undertood the correct UpdateHub probe object.

Fixes zephyrproject-rtos#69297

Signed-off-by: Gerson Fernando Budke <[email protected]>
henrikbrixandersen pushed a commit that referenced this pull request May 29, 2024
After the changes introduced by #50816 the UpdateHub could not decode
anymore the JSON object. This introduce missing parsing definitions
to allow JSON parser undertood the correct UpdateHub probe object.

Fixes #69297

Signed-off-by: Gerson Fernando Budke <[email protected]>
(cherry picked from commit 5fb62ca)
jhedberg pushed a commit that referenced this pull request Jun 2, 2024
After the changes introduced by #50816 the UpdateHub could not decode
anymore the JSON object. This introduce missing parsing definitions
to allow JSON parser undertood the correct UpdateHub probe object.

Fixes #69297

Signed-off-by: Gerson Fernando Budke <[email protected]>
(cherry picked from commit 5fb62ca)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Base OS Base OS Library (lib/os) area: JSON
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON parser fails on multidimensional arrays
9 participants