Skip to content

Preserve XML and HTML text between elements - #205

Open
Shaisolaris wants to merge 1 commit into
trailofbits:masterfrom
Shaisolaris:fix-issue-80-xml-tail
Open

Shaisolaris wants to merge 1 commit into
trailofbits:masterfrom
Shaisolaris:fix-issue-80-xml-tail

Conversation

@Shaisolaris

@Shaisolaris Shaisolaris commented Oct 11, 2026 •

Copy link
Copy Markdown

Fixes #80.

XML and HTML diffs drop text between tags because the model ignores ElementTree.tail. Adding TAIL_ONLY_NEW in <r><a>x</a>TAIL_ONLY_NEW<b>y</b></r> produces a zero-cost match with that text missing from the diff.

Adds tails to XMLElement and XMLElementObj, including traversal, equality, size, copying and compound edits. XML prints tails after the closing tag and preserves whitespace, including trailing newlines. JSON adds a tail field and shows insertions, removals and changes. Its view copies nodes without changing their parents and keeps the edits visible.

The ElementTree parser stays unchanged; #106's HTML parser work is separate. This branch starts from current master, independently of #189 and #190. The JSON node-copying fix overlaps #190, with edit state retained here. The broader format support in #190 and inserted attribute/child fixes in #189 are outside this change.

Tests cover tail-only changes; inserted, removed, changed and unchanged tails in XML and JSON; mixed-content round-trips; whitespace-only tails; escaping and Unicode; nested and root tails; traversal, size and deep copies; edit costs and completion; repeated JSON rendering without changing parents; and inserted/removed children with tails. The issue's example is tested as both XML and HTML. The new regressions fail against unmodified upstream.

Validation:

  • Python 3.12: GRAPHTAGE_TEST_SEED=80 pytest -q: 283 passed, 1,796 subtests passed.
  • Python 3.13 with uv sync --frozen --extra dev: same 283 tests and 1,796 subtests passed.
  • ruff check graphtage test docs bindist: clean, including CI's locked Ruff version.
  • make -C docs html SPHINXOPTS="-W --keep-going": passed with both development and locked Sphinx versions.
  • python -m build --no-isolation: sdist and wheel built.
  • uv lock --check --offline and git diff --check: passed.
  • Four CLI combinations (XML/HTML inputs with XML/JSON output) preserve TAIL_ONLY_NEW with insertion markers and return the expected diff exit status.

This branch has not been deployed

No deployments
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.

Text missing from HTML diff

1 participant