Skip to content

Add regression tests for JsonSerializer.Deserialize<JsonNode> MaxDepth enforcement#3

Draft
Copilot wants to merge 2 commits into
cca-eval-treatmentfrom
copilot/fix-jsonserializer-maxdepth
Draft

Add regression tests for JsonSerializer.Deserialize<JsonNode> MaxDepth enforcement#3
Copilot wants to merge 2 commits into
cca-eval-treatmentfrom
copilot/fix-jsonserializer-maxdepth

Conversation

Copilot AI commented May 27, 2026

Copy link
Copy Markdown

JsonSerializer.Deserialize<JsonNode> was reported as not honoring JsonSerializerOptions.MaxDepth for deeply nested arrays. Investigation confirmed the Utf8JsonReader depth checks (StartArray/StartObject) already enforce the limit correctly — no production code fix was needed. This PR adds the missing regression test coverage.

Tests added

  • DomTests.csDeserializeToNode_RespectsMaxDepth_Arrays and DeserializeToNode_RespectsMaxDepth_Objects: symmetric counterparts to the existing SerializeToNode_RespectsMaxDepth, covering JsonNode, JsonArray, and JsonObject deserialization targets across depths 5, 32, and 70 (above default 64).

  • JsonNodeTests.csDeserialize_JsonNode_RespectsMaxDepth_DeeplyNestedArrays: focused test in the JsonNode-specific class covering the exact repro scenario (e.g. 200 nested arrays with MaxDepth = 32).

Each test verifies that JSON nested exactly at MaxDepth deserializes successfully, while JSON nested one level deeper throws JsonException.

…h enforcement

Adds tests verifying that JsonSerializer.Deserialize<JsonNode/JsonArray/JsonObject>
correctly throws JsonException when MaxDepth is exceeded for deeply nested arrays and
objects, as reported in the issue.

- DomTests.cs: DeserializeToNode_RespectsMaxDepth_Arrays/_Objects (parallel to
  existing SerializeToNode_RespectsMaxDepth)
- JsonNodeTests.cs: Deserialize_JsonNode_RespectsMaxDepth_DeeplyNestedArrays

Co-authored-by: steveisok <471438+steveisok@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix MaxDepth handling in JsonSerializer.Deserialize<JsonNode> Add regression tests for JsonSerializer.Deserialize<JsonNode> MaxDepth enforcement May 27, 2026
Copilot AI requested a review from steveisok May 27, 2026 22:29
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.

JsonSerializer.Deserialize<JsonNode> does not honor MaxDepth for deeply nested arrays

2 participants