fix: strip port from URL domain in is_external_url comparison#1783
Open
Br1an67 wants to merge 1 commit intounclecode:mainfrom
Open
fix: strip port from URL domain in is_external_url comparison#1783Br1an67 wants to merge 1 commit intounclecode:mainfrom
Br1an67 wants to merge 1 commit intounclecode:mainfrom
Conversation
The is_external_url function compared the full netloc (including port) against base_domain (which has port stripped by get_base_domain). This caused URLs like http://localhost:8000/page to be wrongly classified as external when base_domain is 'localhost'. Strip the port from parsed.netloc before comparison. Fixes unclecode#1503
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
is_external_url()comparedparsed.netloc(which includes port, e.g.localhost:8000) againstbase_domain(which has port stripped byget_base_domain()). This caused URLs likehttp://localhost:8000/pageto be wrongly classified as external when the base domain islocalhost, making the crawler stop after the first page whenexclude_external_links=True.The fix strips the port from
parsed.netlocbefore comparison, consistent with howget_base_domain()handles ports.Fixes #1503
List of files changed and why
crawl4ai/utils.py— Strip port from URL netloc inis_external_url()before domain comparisonHow Has This Been Tested?
Verified locally with test cases:
http://localhost:8000/pagewith baselocalhost→ correctly returns internalhttp://localhost:8000/pagewith baselocalhost:8000→ correctly returns internalChecklist: