Skip to content

fix(deep_crawling): allow single-label hostnames#2080

Open
nightcityblade wants to merge 1 commit into
unclecode:mainfrom
nightcityblade:fix/issue-2079
Open

fix(deep_crawling): allow single-label hostnames#2080
nightcityblade wants to merge 1 commit into
unclecode:mainfrom
nightcityblade:fix/issue-2079

Conversation

@nightcityblade

Copy link
Copy Markdown
Contributor

Summary

Fixes #2079.

Allow BFSDeepCrawlStrategy to 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:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas — N/A; the validation removal is self-explanatory.
  • I have made corresponding changes to the documentation — N/A; this is a narrow bug fix with no public API change.
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@keepitdigital

Copy link
Copy Markdown

k

@chuenchen309 chuenchen309 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 new DomainFilter(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.netloc guard (empty netloc → rejected), so nothing new slips through.
  • Unfiltered crawls unchanged in spirit: with no DomainFilter configured, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: BFSDeepCrawlStrategy.can_process_url() rejects valid single-label hostnames (netloc without a dot)

3 participants