fix: Reset private state correctly in sitemap parsers#1938
Merged
Conversation
The XML SAX handler assigned `self.current_tag` instead of `self._current_tag` and the TXT parser assigned `self.buffer` instead of `self._buffer`, so the intended private state was never reset. This left stray inter-element text in the XML buffer and leaked the last URL into subsequent chunks when a TXT parser was reused after `flush()`.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1938 +/- ##
==========================================
+ Coverage 92.95% 92.97% +0.01%
==========================================
Files 167 167
Lines 11708 11708
==========================================
+ Hits 10883 10885 +2
+ Misses 825 823 -2
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:
|
Collaborator
Author
|
@copilot resolve the merge conflicts in this pull request |
Contributor
Resolved the merge conflict and pushed the merge commit in |
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.
Description
Fixes two attribute-name typos in
src/crawlee/_utils/sitemap.pywhere the underscore prefix was missing on assignment, so each statement silently created a new public attribute instead of resetting the intended private state:_XMLSaxSitemapHandler.endElementsetself.current_tag = Noneinstead ofself._current_tag = None. The handler therefore never left the "inside a tracked tag" state, so stray text between elements kept being appended to the buffer and a duplicate close tag could re-process stale buffer contents._TxtSitemapParser.flushsetself.buffer = ''instead ofself._buffer = ''. Reusing the parser afterflush()concatenated the leftover URL with the next chunk, yielding corrupted URLs likehttps://b.com/https://c.com/.Both fixes add the missing underscore. Regression tests cover the state reset in the XML handler and the buffer corruption in the TXT parser.