Skip to content

Comments

Fix incorrect result of .read_text() when it is called after reading Text or GeneralRef event#936

Merged
Mingun merged 3 commits intotafia:masterfrom
Mingun:fix-read-text
Feb 14, 2026
Merged

Fix incorrect result of .read_text() when it is called after reading Text or GeneralRef event#936
Mingun merged 3 commits intotafia:masterfrom
Mingun:fix-read-text

Conversation

@Mingun
Copy link
Collaborator

@Mingun Mingun commented Feb 13, 2026

I found, that due to that we read text and ref data, we skip < at the end of text. Because it is skipped, reading text via .read_text() returns wrong slice:

#[test]
fn text() {
    let mut reader = Reader::from_str(
        "\
        <root>\
            text\
            <root/>\
            <root></root>\
        </root>\
        <element/>",
    );
    assert_eq!(
        reader.read_event().unwrap(),
        Event::Start(BytesStart::from_content("root", 4)),
    );
    assert_eq!(
        reader.read_event().unwrap(),
        Event::Text(BytesText::new("text"))
    );
    assert_eq!(
        reader.read_text(QName(b"root")).unwrap(),
     // "root/><root></root><"  - actual
        "<root/><root></root>"
    );
    assert_eq!(
        reader.read_event().unwrap(),
        Event::Empty(BytesStart::new("element"))
    );
    assert_eq!(reader.read_event().unwrap(), Event::Eof);
}

This PR fixes this bug and opens door for #483

failures:
    borrowed::dangling_amp
    borrowed::text

Diff < left / right > :
<"root/><root></root><"
>"<root/><root></root>"
@Mingun Mingun added the bug label Feb 13, 2026
@codecov-commenter
Copy link

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

Codecov Report

❌ Patch coverage is 88.02817% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.98%. Comparing base (d1acdb5) to head (74bc46e).
⚠️ Report is 33 commits behind head on master.

Files with missing lines Patch % Lines
src/reader/state.rs 83.72% 7 Missing ⚠️
src/reader/buffered_reader.rs 83.87% 5 Missing ⚠️
src/reader/slice_reader.rs 88.00% 3 Missing ⚠️
src/reader/mod.rs 95.12% 2 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #936      +/-   ##
==========================================
- Coverage   58.08%   54.98%   -3.10%     
==========================================
  Files          42       44       +2     
  Lines       15513    16789    +1276     
==========================================
+ Hits         9011     9232     +221     
- Misses       6502     7557    +1055     
Flag Coverage Δ
unittests 54.98% <88.02%> (-3.10%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@Mingun Mingun merged commit 4eb9a40 into tafia:master Feb 14, 2026
7 checks passed
@Mingun Mingun deleted the fix-read-text branch February 14, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants