-
Notifications
You must be signed in to change notification settings - Fork 88
test/json: test array en-/decoding #1278
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
Draft
fAuernigg
wants to merge
3
commits into
baresip:main
Choose a base branch
from
fAuernigg:fix_json_array_encoding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sreimers
reviewed
Mar 11, 2025
Can you please rebase to main, which fixes a run-on-arch CI bug ? |
627478c
to
6aa8360
Compare
6aa8360
to
bb7f1ac
Compare
For now there is only the new unit test. It needs a parsing/encoding fix. |
Not a easy problem to fix and keep backwards compatibility, since always a object is expected on first level for json, the clean solution would be something like this: +++ b/src/json/decode_odict.c
@@ -114,8 +114,24 @@ int json_decode_odict(struct odict **op, uint32_t hash_size, const char *str,
if (err)
return err;
+ struct json_handlers h = {object_handler, array_handler,
+ object_entry_handler, array_entry_handler,
+ o};
+
+ switch (*str) {
+ case '{':
+ container_add(NULL, 0, ODICT_OBJECT, &h);
+ break;
+ case '[':
+ container_add(NULL, 0, ODICT_ARRAY, &h);
+ break;
+ default:
+ return EBADMSG;
+ }
+
+
err = json_decode(str, len, maxdepth, object_handler, array_handler,
- object_entry_handler, array_entry_handler, o);
+ object_entry_handler, array_entry_handler, h.arg);
if (err)
mem_deref(o);
else |
Here is a quick example without breaking the api: |
This was referenced Apr 17, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
JSON array encoding is wrong
This is a unit test to show the bug.
e.g.
Fix will follow.