Skip to content

test(adapters): fix the nesting-depth test under encoding/json v2 - #240

Merged
fredbi merged 1 commit into
go-openapi:masterfrom
fredbi:test/fix-jsonv2
Aug 21, 2026
Merged

test(adapters): fix the nesting-depth test under encoding/json v2#240
fredbi merged 1 commit into
go-openapi:masterfrom
fredbi:test/fix-jsonv2

Conversation

@fredbi

@fredbi fredbi commented Aug 21, 2026

Copy link
Copy Markdown
Member

jlexer counts container depth itself because encoding/json v1's Decoder.Token applies no limit of its own. With v2 (GOEXPERIMENT=jsonv2, the default from go1.27) Token enforces the same 10,000-level ceiling first and reports "exceeded max depth", so asserting our own "maximum nesting depth" wording broke.

The default-limit subtests now only require that the error wraps ErrStdlib, which is the contract either implementation honours. The wording assertion moves to the WithMaxNestingDepth(5) subtest, where our counter fires long before the stdlib's. defaultMaxNestingDepth documents the interaction: a lower limit rejects earlier than the stdlib, a higher one does not lift the stdlib's ceiling on the decode path.

Change type

Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update

Short description

Fixes

Full description

Checklist

  • I have signed all my commits with my name and email (see DCO. This does not require a PGP-signed commit
  • I have rebased and squashed my work, so only one commit remains
  • I have added tests to cover my changes.
  • I have properly enriched go doc comments in code.
  • I have properly documented any breaking change.

jlexer counts container depth itself because encoding/json v1's Decoder.Token
applies no limit of its own. With v2 (GOEXPERIMENT=jsonv2, the default from
go1.27) Token enforces the same 10,000-level ceiling first and reports
"exceeded max depth", so asserting our own "maximum nesting depth" wording
broke.

The default-limit subtests now only require that the error wraps ErrStdlib,
which is the contract either implementation honours. The wording assertion
moves to the WithMaxNestingDepth(5) subtest, where our counter fires long
before the stdlib's. defaultMaxNestingDepth documents the interaction: a
lower limit rejects earlier than the stdlib, a higher one does not lift the
stdlib's ceiling on the decode path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.46%. Comparing base (3fd99ce) to head (83bc7ab).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #240      +/-   ##
==========================================
+ Coverage   93.03%   94.46%   +1.42%     
==========================================
  Files          61       61              
  Lines        3015     3015              
==========================================
+ Hits         2805     2848      +43     
  Misses        166      166              
+ Partials       44        1      -43     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@fredbi
fredbi merged commit 95025ef into go-openapi:master Aug 21, 2026
21 checks passed
@fredbi
fredbi deleted the test/fix-jsonv2 branch August 21, 2026 16:31
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.

1 participant