Add regression tests for JsonSerializer.Deserialize<JsonNode> MaxDepth enforcement#3
Draft
Copilot wants to merge 2 commits into
Draft
Add regression tests for JsonSerializer.Deserialize<JsonNode> MaxDepth enforcement#3Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
…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
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
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.
JsonSerializer.Deserialize<JsonNode>was reported as not honoringJsonSerializerOptions.MaxDepthfor deeply nested arrays. Investigation confirmed theUtf8JsonReaderdepth 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.cs—DeserializeToNode_RespectsMaxDepth_ArraysandDeserializeToNode_RespectsMaxDepth_Objects: symmetric counterparts to the existingSerializeToNode_RespectsMaxDepth, coveringJsonNode,JsonArray, andJsonObjectdeserialization targets across depths 5, 32, and 70 (above default 64).JsonNodeTests.cs—Deserialize_JsonNode_RespectsMaxDepth_DeeplyNestedArrays: focused test in theJsonNode-specific class covering the exact repro scenario (e.g. 200 nested arrays withMaxDepth = 32).Each test verifies that JSON nested exactly at
MaxDepthdeserializes successfully, while JSON nested one level deeper throwsJsonException.