fix(deep_crawling): allow single-label hostnames#2080
Conversation
|
k |
chuenchen309
left a comment
There was a problem hiding this comment.
Reviewed against can_process_url — this looks correct and safe.
The removed "." not in parsed.netloc check was never the domain-restriction mechanism: right below it, if depth != 0 and not await self.filter_chain.apply(url) is what actually enforces DomainFilter/allowed-domains, and that is untouched. So the dot-check was purely a crude structural guard that wrongly rejected valid absolute URLs with a single-label host — not just intranet names but also http://localhost, http://localhost:8080, and Docker/K8s service hostnames, all of which have a non-empty netloc and a valid http(s) scheme.
Points that make this safe:
- No domain/isolation regression: domain scoping still runs through
filter_chain.apply(); single-label hosts now merely reach that filter (exactly what the newDomainFilter(allowed_domains=["intranet"])test asserts) instead of being dropped before it. - Malformed input still rejected: relative paths / sch/netloc-less strings still fail the existing
not parsed.scheme or not parsed.netlocguard (empty netloc → rejected), so nothing new slips through. - Unfiltered crawls unchanged in spirit: with no
DomainFilterconfigured, dotted hosts were already crawled unrestricted; single-label hosts just join them — the user opted into that by not setting a filter.
The regression test is well-targeted (proves the host both reaches and passes the configured filter). LGTM.
Summary
Fixes #2079.
Allow
BFSDeepCrawlStrategyto process valid HTTP(S) URLs whose host is a single label, such as internal DNS names. The existing scheme and non-empty netloc validation continues to reject malformed URLs.List of files changed and why
crawl4ai/deep_crawling/bfs_strategy.py- Remove the overly strict requirement that every hostname contain a dot.tests/deep_crawling/test_deep_crawl_resume.py- Add a regression test proving a single-label hostname reaches and passes the configured domain filter.How Has This Been Tested?
.venv/bin/pytest -q tests/deep_crawling/test_deep_crawl_resume.py— 33 passed..venv/bin/black --check crawl4ai/deep_crawling/bfs_strategy.py tests/deep_crawling/test_deep_crawl_resume.py— run; the command reports existing whole-file formatting drift also present on the upstream baseline. The changed lines were reviewed against Black's diff and introduce no new formatting changes.Checklist: