Skip to content

fix: mark decoded arrays with cjson array metatable#1

Merged
nic-6443 merged 3 commits into
mainfrom
fix-array-mt-20260520123607
May 20, 2026
Merged

fix: mark decoded arrays with cjson array metatable#1
nic-6443 merged 3 commits into
mainfrom
fix-array-mt-20260520123607

Conversation

@jarvis9443
Copy link
Copy Markdown

@jarvis9443 jarvis9443 commented May 20, 2026

Decoded JSON arrays now carry cjson.array_mt, matching cjson.decode_array_with_array_mt(true). This lets callers decode with simdjson and then encode with cjson without turning [] into {}.

This only changes simdjson decode output metadata. The simdjson encoder behavior is unchanged. The test workflow also moves from ubuntu-20.04 to ubuntu-latest because the old runner is no longer usable in this repo.

Tests run:

  • make build
  • PATH=/usr/local/openresty/nginx/sbin:$PATH prove -r t/02-decode.t t/09-empty_array.t
  • make test

CI:

  • Lua Check passed
  • Tests (1.21.4.3) passed
  • Tests (1.25.3.2) passed

Copilot AI review requested due to automatic review settings May 20, 2026 04:38
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

📝 Walkthrough

Walkthrough

Decoder applies cjson.array_mt to arrays constructed during SIMDJSON decoding. Tests were added/updated to assert arrays (including nested and empty) carry cjson.array_mt while objects do not; empty-array round-trip via cjson.encode is verified. CI workflow runner updated to ubuntu-latest.

Changes

cjson Array Metatable Alignment

Layer / File(s) Summary
Decoder array metatable application
lib/resty/simdjson/decoder.lua
Import cjson.array_mt and apply it to tables constructed in _build_array via setmetatable, so decoded arrays carry the same metatable as cjson arrays.
Array metatable verification tests
t/02-decode.t, t/09-empty_array.t
Extended array tests assert cjson.array_mt on outer and nested arrays; object tests assert objects do not use the array metatable. New tests verify empty-array decoding and cjson.encode round-trip.

CI runner update

Layer / File(s) Summary
GitHub Actions runner update
.github/workflows/tests.yml
Change the tests job runner platform from ubuntu-20.04 to ubuntu-latest.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: marking decoded arrays with cjson's array metatable to ensure proper behavior when re-encoding with cjson.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
E2e Test Quality Review ✅ Passed E2E tests verify arrays are marked with cjson.array_mt. Tests cover nested arrays, empty arrays, round-trip encoding in real OpenResty HTTP environment with proper assertions.
Security Check ✅ Passed No security vulnerabilities across 7 categories. PR applies cjson.array_mt metatable to arrays—a standard Lua pattern with no credential exposure, auth issues, or data leakage.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-array-mt-20260520123607

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the decoder so JSON arrays decoded via resty.simdjson are tagged with cjson.array_mt, making them round-trip correctly through cjson.encode (so [] doesn’t become {}), consistent with cjson.decode_array_with_array_mt(true) behavior.

Changes:

  • Set cjson.array_mt on all decoded arrays in the Lua decoder.
  • Extend decode/empty-array tests to assert array metatables (including nested/empty arrays) and validate cjson.encode output.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
lib/resty/simdjson/decoder.lua Marks decoded arrays with cjson.array_mt during table construction.
t/02-decode.t Adds assertions that decoded arrays (including nested arrays) have cjson.array_mt; asserts objects do not.
t/09-empty_array.t Adds a regression test that cjson.encode preserves decoded empty arrays as [].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread t/09-empty_array.t Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Luacheck Report

1 tests   1 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit aa3816e.

♻️ This comment has been updated with latest results.

Copilot AI review requested due to automatic review settings May 20, 2026 04:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread .github/workflows/tests.yml
@nic-6443 nic-6443 merged commit 6e35b1b into main May 20, 2026
12 checks passed
@nic-6443 nic-6443 deleted the fix-array-mt-20260520123607 branch May 20, 2026 05:32
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.

3 participants