Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect end position in read_to_end and read_text #773

Merged
merged 5 commits into from
Jun 27, 2024

Conversation

Mingun
Copy link
Collaborator

@Mingun Mingun commented Jun 27, 2024

When working on #766 I found this bug. When trim_text_start is set to true, the trailing spaces could not be included in text returned by the read_text method and not counted in the end field of the returned span from read_to_end family of methods. If you read text content of such XML:

<tag>  <nested>  </tag>

then the trailing space would be dropped. This is because we detect end position of the span before we read </tag>. When start spaces are trimmed we have 3 events: Start, Empty, End, and buffer_position() after reading each of them are:

<tag>  <nested>  </tag>
     ^         ^ |     ^ - buffer_position() after each event
     ^           ^       - expected Span of the read_to_end() methods

Spaces just skipped and do not update buffer_position() which results to the incorrect end of the Span. This is happened only when the last meaningful event before the closing End event is not a Text event.

Macro moved to helper module because `async-tokio.rs` runs imported `reader.rs` tests,
which is unwanted consequence
failures (3):
  async-tokio (1):
    read_to_end::tag
  reader (2):
    read_to_end::borrowed::tag
    read_to_end::buffered::tag
…art` is set

...and the event before the End event is not a Text event
@Mingun Mingun added the bug label Jun 27, 2024
@Mingun Mingun requested a review from dralley June 27, 2024 07:18
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.37%. Comparing base (7558577) to head (930d1b2).
Report is 54 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     #773      +/-   ##
==========================================
- Coverage   61.81%   60.37%   -1.45%     
==========================================
  Files          41       41              
  Lines       16798    16229     -569     
==========================================
- Hits        10384     9798     -586     
- Misses       6414     6431      +17     
Flag Coverage Δ
unittests 60.37% <ø> (-1.45%) ⬇️

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.

@dralley dralley merged commit 80f0e7c into tafia:master Jun 27, 2024
7 checks passed
@Mingun Mingun deleted the fix-read-to-end branch June 27, 2024 15:09
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