Skip to content

Commit a4f2d77

Browse files
committed
add test to cover invalid User-agent: lines in robots.txt.
1 parent 53b9e2c commit a4f2d77

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/RobotTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,22 @@ public function testCaseSensitivePaths()
171171
$this->assertTrue($g->isAllowed('Googlebot', '/uppercase.html'));
172172
$this->assertFalse($g->isAllowed('Googlebot', '/UPPERCASE.HTML'));
173173
}
174+
175+
/**
176+
* Do not emit an E_NOTICE with an empty needle from strpos when a user-agent line is invalid (empty).
177+
* This effectively ignores the line.
178+
*/
179+
public function testHandlesEmptyUserAgentLine()
180+
{
181+
$invalid_text = <<<EOF
182+
User-agent: foo
183+
User-agent:
184+
Disallow: /
185+
EOF;
186+
187+
$g = new RobotsTxt($invalid_text);
188+
189+
$this->assertFalse($g->isAllowed('foo', '/something'));
190+
$this->assertTrue($g->isAllowed('Googlebot', '/something'));
191+
}
174192
}

0 commit comments

Comments
 (0)