Skip to content

Fix #3 and #4: populate array/object count and enforce string length …#5

Merged
ionux merged 1 commit intomainfrom
claude/review-codebase-roadmap-mbZz5
Mar 5, 2026
Merged

Fix #3 and #4: populate array/object count and enforce string length …#5
ionux merged 1 commit intomainfrom
claude/review-codebase-roadmap-mbZz5

Conversation

@ionux
Copy link
Copy Markdown
Owner

@ionux ionux commented Mar 5, 2026

…limit

#3 - okj_get_array() and okj_get_object() now return an accurate count field by walking the raw JSON text rather than returning 0U unconditionally. Added three static helpers in ok_json.c:

  • okj_skip_string(): advances past a quoted JSON string
  • okj_count_array_elements(): counts comma-delimited elements at depth 1, skipping nested arrays/objects and string content
  • okj_count_object_members(): counts colons at depth 1 (one per member), skipping nested structures and string content

#4 - The string scan loop in okj_parse_value() now breaks when the running length reaches OKJ_MAX_STRING_LEN and returns OKJ_ERROR_MAX_STR_LEN_EXCEEDED instead of scanning unbounded input.

Also changed okj_parse() to propagate the specific error code from okj_parse_value() rather than always returning OKJ_ERROR_PARSING_FAILED, which lets callers distinguish error causes without digging into internals.

Three new tests added (16 total, all passing):

  • test_get_array_count: verifies count == 3 for a three-element array
  • test_get_object_count: verifies count == 2 for a two-member nested object
  • test_string_too_long: verifies OKJ_ERROR_MAX_STR_LEN_EXCEEDED for a 65-character value string (one over the 64-byte limit)

https://claude.ai/code/session_01TFz4uUuUb77evcWUexuxGv

…limit

#3 - okj_get_array() and okj_get_object() now return an accurate count field
by walking the raw JSON text rather than returning 0U unconditionally.
Added three static helpers in ok_json.c:
  - okj_skip_string(): advances past a quoted JSON string
  - okj_count_array_elements(): counts comma-delimited elements at depth 1,
    skipping nested arrays/objects and string content
  - okj_count_object_members(): counts colons at depth 1 (one per member),
    skipping nested structures and string content

#4 - The string scan loop in okj_parse_value() now breaks when the running
length reaches OKJ_MAX_STRING_LEN and returns OKJ_ERROR_MAX_STR_LEN_EXCEEDED
instead of scanning unbounded input.

Also changed okj_parse() to propagate the specific error code from
okj_parse_value() rather than always returning OKJ_ERROR_PARSING_FAILED,
which lets callers distinguish error causes without digging into internals.

Three new tests added (16 total, all passing):
  - test_get_array_count: verifies count == 3 for a three-element array
  - test_get_object_count: verifies count == 2 for a two-member nested object
  - test_string_too_long: verifies OKJ_ERROR_MAX_STR_LEN_EXCEEDED for a
    65-character value string (one over the 64-byte limit)

https://claude.ai/code/session_01TFz4uUuUb77evcWUexuxGv
@ionux ionux merged commit 64bfe9d into main Mar 5, 2026
2 checks passed
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.

2 participants