File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,9 @@ private function parseFile(RobotsFile $robotFile)
6565
6666 $ this ->records = [];
6767 foreach ($ fileRecords as $ record ) {
68+ if (!empty ($ record ['ua ' ])) {
69+ $ record ['ua ' ] = array_filter ($ record ['ua ' ]);
70+ }
6871 if (!empty ($ record ['ua ' ]) && !empty ($ record ['rules ' ])) {
6972 $ this ->records [] = new Record (new UserAgent ($ record ['ua ' ]), new AccessRules ($ record ['rules ' ]));
7073 }
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments