Skip to content

fix: ignore a UTF-8 byte order mark in robots.txt - #2351

Merged
janbuchar merged 1 commit into
apify:masterfrom
RaphaelFakhri:fix/robots-txt-utf8-bom
Oct 26, 2026
Merged

janbuchar merged 1 commit into
apify:masterfrom
RaphaelFakhri:fix/robots-txt-utf8-bom

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

Description

  • RobotsTxtFile.load decodes the response body with utf-8, which keeps a leading UTF-8 byte order mark (BOM) as \ufeff. Protego then does not recognize the first line (\ufeffUser-agent: *) as a User-agent directive, so the rules of the first group are ignored and is_allowed returns True for disallowed paths. With respect_robots_txt_file=True, the crawler fetches pages the site disallows.
  • The body is now decoded with utf-8-sig, which drops the BOM if present and is otherwise identical to utf-8.
  • Adds a regression test that loads a robots.txt with a BOM through the test server.

Issues

Testing

  • New test test_load_robots_txt_with_utf8_bom in tests/unit/_utils/test_robots.py. It fails on master (assert not robots.is_allowed(...) gets True) and passes with the fix, for all HTTP client parametrizations.
  • uv run pytest tests/unit/_utils/test_robots.py: 20 passed.
  • ruff check, ruff format --check, and ty check pass on the changed files.

Checklist

  • CI passed

@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Oct 24, 2026

@Mantisus Mantisus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@apify-approval-mirror apify-approval-mirror Bot 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.

Mirroring approval from @Mantisus.

@janbuchar
janbuchar merged commit 3e6ee66 into apify:master Oct 26, 2026
40 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

robots.txt rules are ignored when the file starts with a UTF-8 byte order mark

4 participants