Skip to content

Commit d60fa8b

Browse files
authored
Merge pull request #15 from nickmoline/master
URL paths in robots.txt are case sensitive
2 parents 2ffea36 + 4670d79 commit d60fa8b

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

src/Robot/RobotsFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RobotsFile implements \Iterator
2222
*/
2323
public function __construct($content)
2424
{
25-
$withoutComments = preg_replace( '/#.*/', '', strtolower($content));
25+
$withoutComments = preg_replace( '/#.*/', '', $content);
2626
$lines = [];
2727

2828
foreach(preg_split("/[\r\n]+/", $withoutComments) as $line) {
@@ -92,4 +92,4 @@ public function rewind()
9292
{
9393
$this->lineIterator->rewind();
9494
}
95-
}
95+
}

src/Robot/RobotsTxt.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ private function parseFile(RobotsFile $robotFile)
4242
$lastDirective = '';
4343

4444
foreach($robotFile as $directive => $value) {
45-
45+
$directive = strtolower($directive);
46+
4647
// add a new record if we have the beginning of a new set of UAs
4748
if ($directive == self::USER_AGENT && $lastDirective != $directive) {
4849
$fileRecords[] = $emptyRecord;
@@ -113,4 +114,4 @@ public function isDisallowed($userAgent, $path)
113114
{
114115
return !$this->isAllowed($userAgent,$path);
115116
}
116-
}
117+
}

tests/RobotTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,17 @@ public function testGooglePrecedenceSpec()
158158
$this->assertTrue($g->isAllowed('Googlebot-Images', '/bot'));
159159
$this->assertTrue($g->isDisallowed('Googlebot-Images', '/news'));
160160
}
161-
}
161+
162+
public function testCaseSensitivePaths()
163+
{
164+
$g = self::getRobotsTxt('caseSensitive');
165+
$this->assertFalse($g->isAllowed('Googlebot', '/lowercase.html'));
166+
$this->assertTrue($g->isAllowed('Googlebot', '/LOWERCASE.HTML'));
167+
168+
$this->assertTrue($g->isAllowed('Googlebot', '/camelcase.html'));
169+
$this->assertFalse($g->isAllowed('Googlebot', '/CamelCase.html'));
170+
171+
$this->assertTrue($g->isAllowed('Googlebot', '/uppercase.html'));
172+
$this->assertFalse($g->isAllowed('Googlebot', '/UPPERCASE.HTML'));
173+
}
174+
}

tests/RobotsFileTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public function newLines()
2727
public function givenCrOnlyLineBreaks_pickUpTwoLines($newline)
2828
{
2929
$test = $this->getTestFile($newline);
30-
$this->assertEquals(['user-agent', '*'], [$test->key(), $test->current()]);
30+
$this->assertEquals(['User-Agent', '*'], [$test->key(), $test->current()]);
3131
$test->next();
32-
$this->assertEquals(['disallow', '/'], [$test->key(), $test->current()]);
32+
$this->assertEquals(['Disallow', '/'], [$test->key(), $test->current()]);
3333
}
34-
}
34+
}

tests/files/caseSensitive.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
User-agent: *
2+
Disallow: /lowercase.html
3+
Disallow: /CamelCase.html
4+
Disallow: /UPPERCASE.HTML
5+
Allow: /

0 commit comments

Comments
 (0)