Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes "case-sensitive" URI matching for Disallow rules in robots.txt #46

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

142 changes: 142 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/RobotsTxt.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ protected function parseUserAgent(string $line): string

protected function parseDisallow(string $line): string
{
return trim(substr_replace(strtolower(trim($line)), '', 0, 8), ': ');
return trim(substr_replace(trim($line), '', 0, 8), ': ');
}

protected function isDisallowLine(string $line): string
Expand Down
9 changes: 9 additions & 0 deletions tests/RobotsTxtTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ public function the_disallows_user_agent_check_is_case_insensitive()
$this->assertFalse($robots->allows('/no-agents', strtolower('UserAgent007')));
}

/** @test */
public function the_disallows_uri_check_is_case_sensitive()
{
$robots = RobotsTxt::readFrom(__DIR__.'/data/robots.txt');

$this->assertFalse($robots->allows('/Case-Sensitive/Disallow'));
$this->assertTrue($robots->allows(strtolower('/Case-Sensitive/Disallow')));
}

/** @test */
public function it_can_handle_multiple_user_agent_query_strings()
{
Expand Down
1 change: 1 addition & 0 deletions tests/data/robots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Disallow: /nl/admin/
Disallow: /en/admin/*
Disallow: /fr/admin$
Disallow: /es/admin-disallow/
Disallow: /Case-Sensitive/Disallow
User-agent: google

Disallow: /
Expand Down
Loading