Skip empty text events after trim_text_end - #986
Open
JerryNee wants to merge 1 commit into
Open
Conversation
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
marked this pull request as ready for review
July 26, 2026 21:56
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Textevents whentrim_text_endremoves their entire contents before markupread_to_endspans while text trimming is enabledRoot cause
ReaderState::emit_texttrimmed text only afterXmlSource::read_texthad 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 returnedEvent::Text("").This changes the private
XmlSource::read_textcontract to detect whitespace-only runs whentrim_text_endis enabled. In that case, the source returns its buffer through the existingMarkuporRefpath, 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_endboundary dependency: its span calculation used the event immediately before an end tag to locate the tag's start.read_to_endnow temporarily disables both text-trimming options while it computes the raw source span, restoring them on every exit path.Validation
cargo fmt --all -- --checkcargo +1.79.0 checkcargo test --all-features --benches --testscargo test --no-default-featurescargo test --features serializecargo test --features serialize,encodingcargo test --features serialize,escape-htmlcargo test --all-featuresRUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-depscargo 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.