Skip to content

Skip empty text events after trim_text_end - #986

Open
JerryNee wants to merge 1 commit into
tafia:masterfrom
JerryNee:agent/fix-trim-text-end-empty-events
Open

Skip empty text events after trim_text_end#986
JerryNee wants to merge 1 commit into
tafia:masterfrom
JerryNee:agent/fix-trim-text-end-empty-events

Conversation

@JerryNee

Copy link
Copy Markdown

Summary

  • skip whitespace-only Text events when trim_text_end removes their entire contents before markup
  • apply the same behavior before general references, across borrowed, buffered, and Tokio readers
  • preserve read_to_end spans while text trimming is enabled
  • enable the existing end-trimming regression test and add focused cross-reader coverage

Root cause

ReaderState::emit_text trimmed text only after XmlSource::read_text had returned a borrowed text slice. If the slice became empty, the parser had already surrendered the reusable buffer and could not safely continue to the following markup or reference, so it returned Event::Text("").

This changes the private XmlSource::read_text contract to detect whitespace-only runs when trim_text_end is enabled. In that case, the source returns its buffer through the existing Markup or Ref path, allowing the state machine to continue without emitting an event. Non-empty text continues through the existing trimming path unchanged.

Skipping the empty event also exposed an existing read_to_end boundary dependency: its span calculation used the event immediately before an end tag to locate the tag's start. read_to_end now temporarily disables both text-trimming options while it computes the raw source span, restoring them on every exit path.

Validation

  • cargo fmt --all -- --check
  • cargo +1.79.0 check
  • cargo test --all-features --benches --tests
  • cargo test --no-default-features
  • cargo test --features serialize
  • cargo test --features serialize,encoding
  • cargo test --features serialize,escape-html
  • cargo test --all-features
  • RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps
  • cargo clippy --all-features --all-targets (completed with pre-existing warnings only)

Closes #984

AI tooling assisted with implementation and test generation. I reviewed and approved the final patch and validation results before submission.

Return the reader buffer directly when trim_text_end removes a whitespace-only run before markup or a reference, allowing parsing to continue without emitting an empty Text event. Preserve read_to_end span boundaries while trimming is enabled.

Closes tafia#984
@JerryNee
JerryNee marked this pull request as ready for review July 26, 2026 21:56
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.07%. Comparing base (e00ae5c) to head (0f9a9dd).
⚠️ Report is 9 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #986      +/-   ##
==========================================
- Coverage   57.31%   57.07%   -0.24%     
==========================================
  Files          46       47       +1     
  Lines       18197    18560     +363     
==========================================
+ Hits        10429    10594     +165     
- Misses       7768     7966     +198     
Flag Coverage Δ
unittests 57.07% <100.00%> (-0.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

trim_text_end still emits an empty Text event for whitespace-only text before a tag

2 participants