Skip to content

Conversation

@alexeyzimarev
Copy link
Member

@alexeyzimarev alexeyzimarev commented Jan 12, 2026

User description

Description

Replaces #2336


Auto-created Ticket

#2340

PR Type

Bug fix


Description

  • Fix XmlDeserializer to use Elements() instead of Descendants() for nested XML elements

  • Prevent deeply nested elements from being incorrectly included in parent lists

  • Handle duplicate element names by preferring shallowest RootElement match

  • Remove null values from namespace filtering and fix null-forgiving operators


Diagram Walkthrough

flowchart LR
  A["XmlDeserializer"] -->|"RootElement selection"| B["Prefer shallowest match<br/>Element() then DescendantsAndSelf()"]
  A -->|"HandleListDerivative"| C["Use Elements() on containers<br/>Descendants() as fallback"]
  A -->|"RemoveNamespace"| D["Filter null attributes"]
  A -->|"Type conversion"| E["Remove null-forgiving operators"]
Loading

File Walkthrough

Relevant files
Bug fix
XmlDeserializer.cs
Refactor nested element handling with Elements() strategy

src/RestSharp.Serializers.Xml/XmlDeserializer.cs

  • Modified RootElement selection to prefer shallowest match using
    Element() first, then DescendantsAndSelf() ordered by ancestor count
  • Refactored HandleListDerivative to detect container elements and use
    Elements() for direct children only, preventing nested list flattening
  • Extracted element name variation logic into new
    TryFindElementsByNameVariations() method supporting both direct
    children and descendants modes
  • Added IsValidXmlElementName() helper to filter out generic type names
    containing backticks
  • Fixed RemoveNamespace() to filter null attribute values
  • Removed unnecessary null-forgiving operators (!) from ToString() calls
+117/-29
Tests
NestedElementTestClasses.cs
Add test classes for nested element scenarios                       

test/RestSharp.Tests.Serializers.Xml/SampleClasses/NestedElementTestClasses.cs

  • Added Item class with recursive SubItems list for testing nested
    structures
  • Added ItemContainer class to hold list of Items
  • Added ItemWithGroup and ItemGroup classes for testing grouped nested
    items
  • Added ItemsResponse class for testing complex nested scenarios
+25/-0   
XmlDeserializerTests.cs
Add comprehensive tests for nested element fixes                 

test/RestSharp.Tests.Serializers.Xml/XmlDeserializerTests.cs

+165/-1 

Copilot AI and others added 2 commits January 6, 2026 23:27
…sted XML

* Fix XmlDeserializer nested element bugs

- Fix Bug #1: HandleListDerivative now uses Elements() on containers instead of Descendants()
- Fix Bug #2: Deserialize RootElement selection prefers shallowest match
- Fix Bug #3: RemoveNamespace filters null values
- Add comprehensive tests for all three fixes
@qodo-free-for-open-source-projects
Copy link
Contributor

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
🟢
No codebase code duplication found New Components Detected (Top 5):
- Deserialize_Nested_List_Should_Not_Include_Deeply_Nested_Items
- Deserialize_RootElement_Should_Not_Throw_On_Duplicate_Nested_Names
- Deserialize_RootElement_Should_Prefer_Shallowest_Match
- Deserialize_RootElement_Should_Try_Direct_Child_First
- Deserialize_List_With_Container_Should_Use_Direct_Children_Only
Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-free-for-open-source-projects
Copy link
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@alexeyzimarev alexeyzimarev merged commit bc2ae9c into dev Jan 12, 2026
10 checks passed
@alexeyzimarev alexeyzimarev deleted the pr-2336 branch January 12, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants