fix: handle compound extensions in LinkExtractor#351
Open
axelray-dev wants to merge 1 commit into
Open
Conversation
_url_extension() returns only the last suffix (e.g. 'gz' for 'dataset.tar.gz'), so compound extensions like 'tar.gz' listed in IGNORED_EXTENSIONS never match during deny_extensions filtering. Add _url_extensions() helper returning all dot-suffixes for the last path segment and use it in _url_passes() so that compound extensions are correctly rejected. Fixes D4Vinci#349
Contributor
|
Confirmed this fixes it. Only nit: |
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.
Proposed change
_url_extension()returns only the last suffix of a URL path segment (e.g."gz"fordataset.tar.gz). This means compound extensions like"tar.gz"that are already listed inIGNORED_EXTENSIONSnever match duringdeny_extensionsfiltering, so archive files such as.tar.gzand.tar.bz2pass through the extractor undetected.This PR adds a
_url_extensions()helper that returns all dot-suffixes for the last path segment (e.g.{"gz", "tar.gz"}fordataset.tar.gz) and uses it in_url_passes()so compound extensions are correctly rejected. The existing_url_extension()function is preserved unchanged for backward compatibility.Type of change:
Additional information
pytest tests/spiders/test_links.py -v-- 34/34 passedruff checkandruff format --checkboth cleangit diff --checkcleanChecklist: