Skip to content

xml: verify nested closing tag names in readContent #134

@vmvarela

Description

@vmvarela

Description

In `src/xml.zig`, `XmlParser.readContent` tracks nesting depth correctly but discards the closing tag name for nested elements (depth > 0):

```zig
// Closing tag of a nested element
depth -= 1;
self.advance(); self.advance(); // "</"
_ = self.readName(err_writer); // name read and discarded
```

This means `text` is accepted without error (content captured as raw XML, which is the intended behaviour for mixed/nested content).

For the primary use case of sql-pipe (row-based XML with plain text column values) this causes no data corruption — `depth == 0` closing tags are fully verified. The issue only surfaces for deeply-nested, malformed XML where the parser is silently lenient.

Acceptance Criteria

  • Maintain a stack of open element names inside `readContent`
  • On each closing tag at `depth > 0`, verify the name matches the top of the stack; `fatalAt` on mismatch
  • Existing tests (unit + integration) continue to pass
  • Add a unit test that exercises mismatched nested tags

Notes

Requires an internal `ArrayList([]const u8)` stack inside `readContent`, allocated with the existing `allocator` parameter. No API changes needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:lowNice to have, do when possiblesize:sSmall — 1 to 4 hourstech-debtTechnical debt — address proactivelytype:choreMaintenance, refactoring, tooling

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions