Skip to content

fix(deep-crawling): allow single-label hostnames in can_process_url validation - #2143

Open
Bruce-Yii wants to merge 1 commit into
unclecode:developfrom
Bruce-Yii:fix/bfs-single-label-hostnames
Open

fix(deep-crawling): allow single-label hostnames in can_process_url validation#2143
Bruce-Yii wants to merge 1 commit into
unclecode:developfrom
Bruce-Yii:fix/bfs-single-label-hostnames

Conversation

@Bruce-Yii

Copy link
Copy Markdown

Summary

Fixes #2079

BFSDeepCrawlStrategy.can_process_url() and BestFirstCrawlingStrategy.can_process_url() rejected any URL whose netloc contains no dot (Invalid domain), silently dropping valid internal targets such as intranet hosts, localhost (with or without a port) and Docker service names during deep crawls. The error was raised before the configured FilterChain was ever applied.

The scheme (http/https) and non-empty netloc checks are kept; only the dot heuristic is removed, so https://name/xyz now passes validation and reaches the filter chain.

List of files changed and why

  • crawl4ai/deep_crawling/bfs_strategy.py - Remove the dot requirement from URL validation in can_process_url.
  • crawl4ai/deep_crawling/bff_strategy.py - Same fix for the best-first strategy.
  • tests/deep_crawling/test_can_process_url.py - New parametrized tests covering single-label hosts, localhost with port, IP literals, rejection of missing scheme/netloc and non-http(s) schemes, and filter-chain behavior at depth > 0.

How Has This Been Tested?

  • pytest tests/deep_crawling/test_can_process_url.py -v18 passed
  • pytest tests/deep_crawling/ → 85 passed; the 2 failures in test_deep_crawl_resume_integration.py are pre-existing environment issues (they require launching a real Playwright Chromium, which is not available in this dev venv) and fail identically on unmodified develop
  • ruff check --select E9,F63,F7,F82 on the changed files → clean
  • python -m py_compile on the changed files → clean

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
  • I have made corresponding changes to the documentation
  • 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

…alidation

BFSDeepCrawlStrategy and BestFirstCrawlingStrategy rejected any URL whose
netloc contains no dot, which dropped valid internal targets such as
intranet hosts, localhost (with or without a port) and Docker service
names. Scheme and netloc checks remain; only the dot heuristic is removed.

Fixes unclecode#2079

Copy link
Copy Markdown
Author

Quick follow-up after re-validating this against the latest develop:

  • The original single-label hostname check is still present upstream in both BFS and BestFirst strategies.
  • This patch still applies cleanly with no conflicts.
  • Targeted regression tests: 18/18 passed.
  • Deep-crawling suite: 85 passed, 2 failed; the same 2 Playwright/Chromium-dependent failures reproduce on a clean upstream/develop worktree, so they are unrelated to this PR.
  • Ruff checks and py_compile are clean.
  • Re-checked the behavior for localhost, single-label/Docker service hostnames, IP literals, invalid schemes/empty netloc, and FilterChain execution.

No rebase or code changes were needed. Happy to adjust the approach if you prefer a different validation rule.

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.

1 participant